fengrengui

导航

一个update的触发器

用户要求保留删除的数据,我决定加一个DeleteTime字段,作为标记,deletetime为不为空说明数据已经删除。

create TRIGGER dbo.AfterApplicationDelete
ON dbo.tb_Applications
for update

AS
declare @DeleteTime datetime
set @DeleteTime=(select DeleteTime from inserted)

if(update(DeleteTime) and (@DeleteTime is not null))
begin

 update tb_Org_Application
 set DeleteTime=getdate()
 where AppID in (select [ID] from inserted)
 
 update tb_Process_Application
 set DeleteTime=getdate()
 where ApplicationID in (select [ID] from inserted)
 
 update tb_Modules
 set DeleteTime=getdate()
 where ApplicationID in (select [ID] from inserted)

 update tb_Org_Process_Application
 set DeleteTime=getdate()
 where ApplicationID in (select [ID] from inserted)
 
end

posted on 2006-05-23 09:17  阿贵  阅读(788)  评论(0)    收藏  举报