第十二 SQL模拟转账(事务)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.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