欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL Server 触发器 表的特定字段更新时,触发Update触发器

程序员文章站 2023-12-10 19:10:04
复制代码 代码如下: create trigger tr_mastertable_update on mastertable after update as if upda...
复制代码 代码如下:

create trigger tr_mastertable_update
on mastertable
after update
as
if update ([type])--当type字段被更新时,才会触发此触发器
insert into masterlogtable
select
id
,(case [type] when 1 then 'type1'
when 2 then 'type2'
when 3 then 'type3'
when 4 then 'type4'
else 'typedefault'
end)
,name
from inserted
go

另外再补充一句:insert和update的数据都会保存在临时表中,所以使用inserted可以取出这些数据,删除时使用deleted可以取出被删除的数据
转载请标明出处:http://blog.csdn.net/tjvictor