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

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

发布时间:2020-12-12 09:35:23 所属栏目:MsSql教程 来源:网络整理
导读:div class="codetitle" a style="CURSOR: pointer" data="16038" class="copybut" id="copybut16038" onclick="doCopy('code16038')" 代码如下:div class="codebody" id="code16038" create trigger TR_MasterTable_Update on MasterTable after update as i

<div class="codetitle"><a style="CURSOR: pointer" data="16038" class="copybut" id="copybut16038" onclick="doCopy('code16038')"> 代码如下:<div class="codebody" id="code16038">
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

(编辑:李大同)

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

    推荐文章
      热点阅读