开始事物:begin transaction
提交事物:commit transaction
回滚事物:rollback transaction
begin transaction declare @errorSum int --定义局部变量 set @errorSum=0 --初始化临时变量 update bank set currentMoneycurrentMoney= currentMoney-1000 where customerName='张三' set @errorSum=@errorSum+@@error --累计是否有错误 update bank set currentMoneycurrentMoney= currentMoney+1000 where customerName='李四' set @errorSum=@errorSum+@@error --累计是否有错误 if @errorSum<>0 --如果有错误 begin rollback transaction end else begin commit transaction end go