触发器:删除的时候触发并记录信息

--创建delete触发器备份记录

CREATE TRIGGER trig_delete_mzy_request
   ON mzy_request  --对这张表的删除操作进行触发行动
   for delete
AS 
BEGIN

    DECLARE @IP_Address varchar(50)=''; 

    SELECT TOP 1 @IP_Address=client_net_address --获取操作的IP地址
    FROM sys.dm_exec_connections  
    WHERE session_id = @@SPID; 
  --插入数据 
  insert into mzy_request_delete_log select *,GETDATE() as DeleteTime,@IP_Address AS IpAddress from Deleted;  

END

 感谢:https://blog.csdn.net/cb168/article/details/8457195

posted @ 2018-05-02 14:10  蜗牛的礼物  阅读(478)  评论(0编辑  收藏  举报