BEGIN TRANSACTION
COMMIT TRANSACTION
ROLLBACK TRANSACTION
一旦事务提交或回滚,则事务结束
use StudentManager
go
declare @errorSum int
set @errorSum=0
begin transaction
begin
。。。update/insert/delete语句
update CardAccount set CurrentMoney = CurrentMoney-1000 where StudentId = 100001
set @errorSum=@errorSum+@@ERROR
update CardAccount set CurrentMoney = CurrentMoney+1000 where StudentId=100002
set @errorSum=@errorSum+@@ERROR
if(@errorSum>0)
rollback transaction
else
commit transaction
end
go