加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 07:53:20 所属栏目:MsSql教程 来源:网络整理
导读:感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧! 代码如下: create trigger TR_MasterTable_Update on MasterTable after update as if update ([Type])--当Type字段被更新时,才会触发此触发器 insert into MasterLogTable select Id,

感兴趣的小伙伴,下面一起跟随编程之家 52php.cn的小编两巴掌来看看吧!

代码如下:

 
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读