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

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

WBOY
WBOYOriginal
2016-06-07 17:58:491408browse

另外再补充一句:insert和update的数据都会保存在临时表中,所以使用inserted可以取出这些数据,删除时使用deleted可以取出被删除的数据

代码如下:
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
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn