declare @index int set @index=0while(@index < 21) BEGIN TRY -- Generate a divide-by-zero error. SELECT 1/0; END TRY BEGIN CATCH SELECT ERROR_LINE() AS ErrorLine; END CATCH; set @index = @index + 1
declare @index int set @index=0while(@index < 21) begin BEGIN TRY -- Generate a divide-by-zero error. SELECT 1/0; END TRY BEGIN CATCH SELECT ERROR_LINE() AS ErrorLine; END CATCH;set @index = @index + 1 end
user tempdb go create table ta (id int identity(1,1) , sname uniqueidentifier) create table tb (id int ,sname uniqueidentifier) insert into ta values (newid()) go 100declare @i int set @i=1 while @i<=(select max(id) from ta ) begin begin tran insert into tb select * from ta where id =@i set @i=@i+1 commit tran if(@@error<>0) Rollback tran end
declare @index int
set @index=0while(@index < 21)
BEGIN TRY
-- Generate a divide-by-zero error.
SELECT 1/0;
END TRY
BEGIN CATCH
SELECT ERROR_LINE() AS ErrorLine;
END CATCH;
set @index = @index + 1
set @index=0while(@index < 21)
begin
BEGIN TRY
-- Generate a divide-by-zero error.
SELECT 1/0;
END TRY
BEGIN CATCH
SELECT ERROR_LINE() AS ErrorLine;
END CATCH;set @index = @index + 1
end
user tempdb
go
create table ta (id int identity(1,1) , sname uniqueidentifier)
create table tb (id int ,sname uniqueidentifier)
insert into ta values (newid())
go 100declare @i int
set @i=1
while @i<=(select max(id) from ta )
begin
begin tran
insert into tb
select * from ta
where id =@i
set @i=@i+1
commit tran
if(@@error<>0)
Rollback tran
end