zoukankan      html  css  js  c++  java
  • 【SQL SERVER】更新触发器获取更新行的数据

    • sql update 触发器 获得被update的行的信息 
    create trigger TgName 
    on tb 
    for update 
    as 
        if update(recommend) 
    begin 
    update tb set commenddate=(getdate()) from tb inner join inserted on tb.vlistid=Inserted.vlistid 
    end 

    关键在于Inserted
    触发器语句中使用了两种特殊的表:deleted 表和 inserted 表。
    Deleted 表用于存储 DELETE 和 UPDATE 语句所影响的行的复本。在执行 DELETE 或 UPDATE 语句时,行从触发器表中删除,并传输到 deleted 表中。
    Deleted 表和触发器表通常没有相同的行。

    Inserted 表用于存储 INSERT 和 UPDATE 语句所影响的行的副本。在一个插入或更新事务处理中,新建行被同时添加到 inserted 表和触发器表中。
    Inserted 表中的行是触发器表中新行的副本。 

    1.插入操作(Insert)
    Inserted表有数据,Deleted表无数据

    2.删除操作(Delete)
    Inserted表无数据,Deleted表有数据

    3.更新操作(Update)
    Inserted表有数据(新数据),Deleted表有数据(旧数据)

  • 相关阅读:
    常春藤之路,从幼儿园开始走起
    常青藤零距离
    web-service
    WebService到底是什么?
    How to add libraries to “External Libraries” in WebStorm/PhpStorm/Intellij
    浏览器核心说明
    万维网
    js和jquery获取span里面的值
    TPshop学习
    sphinx文档
  • 原文地址:https://www.cnblogs.com/WilsonPan/p/2533259.html
Copyright © 2011-2022 走看看