……………………………………………………………………………………………………………………………………
>创建UPDATE触发器
use studb
go
if exists (select * from sysobjects where name = ''trigger_update_bank'')
drop trigger trigger_update_bank
create trigger trigger_update_bank
on bank
for update
as
declare @beforemoney money,@aftermoney money
select @beforemoney = currentmoney from deleted
select @aftermoney = currentmoney from inserted
if abs(@aftermoney - @beforemoney)>20000
begin
print ''交易金额:''+convert(varchar(20),abs(@aftermoney-@beforemoney))
raiserror (''每笔交易不能超过2万元,交易失败'',16,1)
rollback transaction
end
go
set nocount on
update bank set currentmoney = currentmoney + 25000 where cardid = ''001''
insert into transinfo (cardid,transtype,transmoeny) values (''002'',''支取'',30000)
insert into transinfo (cardid,transtype,transmoeny) values (''002'',''存入'',5000)
go
print ''帐户信息表中的数据:''
select * from bank
print ''交易信息表中的数据:''
select * from transinfo
use studb
go
if exists (select * from sysobjects where name = ''trigger_update_transinfo'')
drop trigger trigger_update_transinfo
go
create trigger trigger_update_transinfo
on transinfo
for update
as
if update (transdate) ------检查是否修改了交易日期列
begin
print ''交易失败。。。''
raiserror (''安全警告:交易日期不能修改,由系统自动产生'',16,1)
rollback transaction
end
go
set nocount on
update transdate set transdate = ''2000-1-1''
go
&n