-------------事务
declare @zhuan int =1000
declare @sumerr int
=0
begin transaction --开始事务(告诉数据库事务启动)
update dbo.bank set balance=
balance-@zhuan where cid=‘0001‘
set @sumerr=@sumerr+@@ERROR
update
dbo.bank set balance= balance+@zhuan where cid=‘0002‘
set
@sumerr=@sumerr+@@ERROR
if(@sumerr >0)--全局变量,输出错误码(错误码大于零)
begin
rollback
transaction --回滚事务,放弃事务,放弃操作----失败
end
else
begin
commit transaction --提交事务--成功
end
原文:http://www.cnblogs.com/sumg/p/3649488.html