create trigger tri_update
on UserCardInfo
for update
as
begin
declare @ALLMoney int
declare @OutMoney int
select @ALLMoney = CardMoney from UserCardInfo
declare @No varchar(50)
declare @Name varchar(50)
declare @Money varchar(50)
begin try
begin transaction
if @OutMoney<=@ALLMoney
begin
update UserCardInfo set CardMoney = CardMoney - @OutMoney
select @No=CardNo,@Name=Name ,@Money = CardMoney from inserted
insert into CardOperation values (@No,@Name,@Money,'取款')
end
commit transaction
end try
begin catch
rollback transaction
end catch
end
转载于:https://www.cnblogs.com/NETSBW/p/7883602.html