确保语句所有执行成功,如果其中一条不满足,则为失败,进行回滚操作
begin transaction declare @myerror int=0 UPDATE BankCard SET CardMoney=CardMoney-10000 where CardNo='6225125478544587' set @[email protected][email protected]@ERROR INSERT into CardExchange(CardNo,MoneyInBank,MoneyOutBank,ExchangeTime) values ('6225125478544587',1,0,getdate()) IF @myerror=0 begin COMMIT TRANSACTION print '取款成功' END else BEGIN rollback TRANSACTION print '取款失败' END