select * from bank insert into bank values(10000) insert into bank values(20000) --打开一个事务 begin tran --定义临时变量 declare @num int = 0; update bank set balance=balance-15000 where Id=1 set @num = @num + @@error; --上一条语句出错次数 update bank set balance=balance+15000 where Id=2 set @num = @num + @@error; if @num <> 0 begin --回滚事务 rollback tran end else begin --提交事务 commit tran end
时间: 2024-10-10 03:42:36