![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
--模拟转账(事务) begintransaction declare @errorSum int set @errorSum=0 update Customer set CurrentMoney=CurrentMoney-500 where [Name]='张三' set @errorSum=@errorSum+@@error update Customer set CurrentMoney=CurrentMoney+500 where [Name]='李四' set @errorSum=@errorSum+@@error printconvert(varchar(50),@errorSum) if(@errorSum<>0) begin print'回滚事务,还原到更新前的数据状态' rollbacktransaction end else begin print'提交事务,对数据库的修改是永久的' committransaction end go