create trigger trig_Bank
on bank
for update
as
declare @newMoney money
declare @oldMoney money
declare @money money
declare @cardId char(9)
select @cardId=cardId,@newMoney=currentMoney from inserted
select @oldMoney=currentMoney from deleted
set @money= abs(@newMoney-@oldMoney)
if(@money>20000)
begin
raiserror('每笔交易金额不能超过20000元,交易失败',6,1)
print('交易金额:'+convert(varchar(20),@money))
rollback
end
else
begin
print('交易成功!交易金额:'+convert(varchar(20),@money))
print('帐号:'+convert(varchar(20),@cardId)+'帐户余额:'+convert(varchar(20),@newMoney))
end
go