触发器- Elvis Wu - JavaEye技术网站
use northwind;
go
/****************************************************
 * 删除cust_test表的记录时,
 * 同时删除order_test表中的关联数据
 ****************************************************/
create trigger cust_order_del1
on cust_test
after delete
as
delete from order_test
where customerID in 
(
select id from deleted
)
go

/****************************************************
 * 插入order_test表时,如果cust_test表中关联记录的
 * locked字段为1,则事务回滚,不允许插入
 ****************************************************/
create trigger cust_order_ins2
on order_test
after insert
as
if(select locked from cust_test, inserted where cust_test.id=inserted.customerID)=1
begin
print 'The goods is beging processed'
rollback transaction
end
go
/****************************************************
?* 插入order_test记录时,关联的cust_test记录中的数量要减少
?****************************************************/
create trigger order_cust_ins3
on order_test
after insert
as
update cust_test set cust_test.account=cust_test.account-inserted.account
from cust_test, inserted 
where cust_test.id=inserted.customerid
/****************************************************
?* 不允许修改orderDate字段
?****************************************************/
create trigger order_upd4
on order_test
after update
as
if(select orderdate from inserted) is not null
begin
print 'can not update orderdate'
rollback transaction
end

?

郑重声明:资讯 【触发器- Elvis Wu - JavaEye技术网站】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——