create database temp_database use temp_database create table account ( ID int primary key not null, amount int not null ) insert account values(1,200) insert account values(2,399) begin transaction update account set amount = amount + 200 where ID = 1 if (@@ERROR = 0) begin update account set amount = amount -200 where ID = 2 if(@@ERROR = 0) commit transaction --操作成功 提交事务 else rollback transaction --操作失败 回滚事务(第二次操作) end else rollback transaction --操作失败 回滚事务(第一次操作) go use master drop database temp_database