日期:2014-05-19  浏览次数:20481 次

新手,求一简单的触发器,谢谢大家
表名:ed_reports

主键   Reports_id
字段   reportstype
字段   Reports_clshow


当此ed_reports表中记录执行修改时候
1)如果修改记录完后reportstype   =2   时候执行下面操作,不等于2的时候不执行下面操作
2)向   ed_reportslog   表中插入相同的记录,并且删除   ed_reports   表中的原记录


------解决方案--------------------
create trigger tr_ed_reports_Update
on ed_reports
for update
as
set nocount on

insert ed_reportslog (Reports_id,
reportstype,
Reports_clshow
)
select
Reports_id,
reportstype,
Reports_clshow
from inserted
where reportstype =2

delete a
from ed_reports a,inserted i
where i.reportstype =2
and i.Reports_id=a.Reports_id

go