--SQL SERVER触发器:独立于程序之外的纯数据库逻辑,因数据变动而触发,插入,修改,删除
create TRIGGER a ON [dbo].[bd_option]
FOR INSERT
AS
insert into cn_itemoption (cuid,pdno,pdnm,opid,opno,opnm,type,icst,quty,pric)
select newid(),'A','A',opno,opno,opnm,type,pric,1,pric from inserted
insert into cn_ppcost (pdno,pdnm,opid,opno,opnm,numb,quty,pric)
select 'A','A',opno,opno,opnm,1,1,pric from inserted
-------------
create TRIGGER b ON [dbo].[bd_option]
FOR update
AS
update cn_itemoption
set opnm=y.opnm
from cn_itemoption x,inserted y
where x.opno=y.opno
update cn_ppcost
set opnm=y.opnm
from cn_ppcost x,inserted y
where x.opno=y.opno
create TRIGGER c ON [dbo].[bd_option]
FOR DELETE
AS
delete cn_itemoption
where opno in (select opno from deleted )
delete cn_ppcost
where opno in (select opno from deleted )
create TRIGGER a ON [dbo].[bd_option]
FOR INSERT
AS
insert into cn_itemoption (cuid,pdno,pdnm,opid,opno,opnm,type,icst,quty,pric)
select newid(),'A','A',opno,opno,opnm,type,pric,1,pric from inserted
insert into cn_ppcost (pdno,pdnm,opid,opno,opnm,numb,quty,pric)
select 'A','A',opno,opno,opnm,1,1,pric from inserted
-------------
create TRIGGER b ON [dbo].[bd_option]
FOR update
AS
update cn_itemoption
set opnm=y.opnm
from cn_itemoption x,inserted y
where x.opno=y.opno
update cn_ppcost
set opnm=y.opnm
from cn_ppcost x,inserted y
where x.opno=y.opno
create TRIGGER c ON [dbo].[bd_option]
FOR DELETE
AS
delete cn_itemoption
where opno in (select opno from deleted )
delete cn_ppcost
where opno in (select opno from deleted )