begin try
begin transaction
insert into TableA ...
insert into TableB ...
insert into TableC ...
commit transaction
end try
begin catch
-- need to handle error
rollback transaction
end catch
游标方法:
declare @name varchar(20)
Declare Cur Cursor For
select Name from 表
declare @SQL Varchar(2000)
Open Cur
Fetch Cur Into @name
While @@FETCH_STATUS=0
BEGIN
--构造你的SQL(多个插入语句,控制好并发)
Exec(@sql)
Fetch Cur Into @name
End
Close Cur
Deallocate cur
(程序用循环插入):
insert into 表1(...) select 'a'...
go
insert into 表2(...) select 'a'...
go