SQL SERVER 通过触发器实现delete数据备份,触发器脚本如下:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[tgr_a_user_delete]
ON [dbo].[A_User]
for delete
AS
BEGIN
if (object_id('A_UserBak', 'U') is not null)
begin
--存在A_UserBak,直接插入数据
insert into A_UserBak select *,GETDATE() as DeleteTime from deleted;
end
else
begin
--不存在A_UserBak创建再插入
select *,GETDATE() as DeleteTime into A_UserBak from deleted;
end
END
GO
希望以上分享对初学朋友有些帮助,谢谢!
更多关注付义方技术博客:http://blog.csdn.net/fuyifang
或者直接用手机扫描二维码查看更多博文:
Author : 付义方