zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

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

SQLServer 触发器 更新 特定 update 触发
2023-06-13 09:14:12 时间
复制代码代码如下:

createtriggerTR_MasterTable_Update
onMasterTable
afterupdate
as
ifupdate([Type])--当Type字段被更新时,才会触发此触发器
insertintoMasterLogTable
select
Id
,(Case[Type]when1then"Type1"
when2then"Type2"
when3then"Type3"
when4then"Type4"
else"TypeDefault"
end)
,Name
frominserted
go

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