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


 
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可以取出被删除的数据


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM