SqlServer触发器的应用- jiangchongwei - 博客园

一、insert触发器----------------

create trigger tr_COMMISSIONINFO_INSERT on COMMISSION_INFO_
for insert
as
begin
 declare @COMMISSIONID varchar(20),@DATE datetime 
 set @COMMISSIONID=(select ID_ from INSERTED)
 set @DATE=getdate()
 insert into COOPERATE_YEARS_(COMMISSION_ID_, CONTRACT_START_DATE_, RE_CONTRACT_START_DATE_) VALUES(@COMMISSIONID, @DATE, @DATE)
end

二、update触发器

 create trigger tr_COMMISSIONINFO_UPDATE on COMMISSION_INFO_
for update
as
begin
 declare @COMMISSIONID varchar(20), @OLD_COMM_CATEGORY int, @NEW_COMM_CATEGORY int, @DATE datetime 
 set @COMMISSIONID=(select ID_ from INSERTED)
    set @OLD_COMM_CATEGORY=(select COMM_CAGEGORY_ from DELETED)
    set @NEW_COMM_CATEGORY=(select COMM_CAGEGORY_ from INSERTED)
 set @DATE=getdate()
    if((@OLD_COMM_CATEGORY<103 or @OLD_COMM_CATEGORY>106) and (@NEW_COMM_CATEGORY>=103 and @NEW_COMM_CATEGORY<=106))
    begin
        if exists(select 1 from COOPERATE_YEARS_ where )
        begin
            update COOPERATE_YEARS_ set where
        end
        else
        begin
            insert into COOPERATE_YEARS_(COMMISSION_ID_, CONTRACT_START_DATE_, RE_CONTRACT_START_DATE_)VALUES(@COMMISSIONID, @DATE, @DATE)
        end
    end
end

 

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