begin tran--事务开始
--用游标
declare @uname varchar(200)
declare cur1 cursor for select uname from table1 where uid=1
open cur1
fetch next from cur1 into @uname
while @@fetch_status=0
begin
--写入你要处理的语句
......
if @@error<>0 --出现错误,回滚
rollback tran
fetch next from cur1 into @uname
end
commit tran--如果没问题,提交
close cur1
deallocate cur1
--用游标
declare @uname varchar(200)
declare cur1 cursor for select uname from table1 where uid=1
open cur1
fetch next from cur1 into @uname
while @@fetch_status=0
begin
--写入你要处理的语句
......
if @@error<>0 --出现错误,回滚
rollback tran
fetch next from cur1 into @uname
end
commit tran--如果没问题,提交
close cur1
deallocate cur1
begin tran--事务开始--用游标
declare @uname varchar(200)
declare cur1 cursor for select uname from table1 where uid=1
open cur1
fetch next from cur1 into @uname
while @@fetch_status=0
begin
--写入你要处理的语句
......
fetch next from cur1 into @uname
end
commit tran--如果没问题,提交
close cur1
deallocate cur1
后就不用
if @@error<>0 --出现错误,回滚
rollback tran
这一句是吗?
close cur1
deallocate cur1
后还要执行其他sql操作
我想放在同一个事务中来做,请问commit tran应该放在什么位置?
set xact_abort on
还没有用过,试试!