确保语句所有执行成功,如果其中一条不满足,则为失败,进行回滚操作
关键字:tansaction
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
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280415.html