如何创建将删除的数据(多个记录)保存到生产表的触发器 [英] How to create a trigger that would save the deleted data (multiple records) to a Production Table

查看:68
本文介绍了如何创建将删除的数据(多个记录)保存到生产表的触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用临时表来保持sql-server的良好性能,我拥有该表(生产表)的副本,我创建了一个触发器,当我从临时表中删除数据时,该触发器会将数据插入到生产表。问题是,当我从临时表中删除数据记录时,它仅插入第一条记录。

I use a temporary table to keep a good performance of sql-server, I have a copy of that table (production table), I created a trigger that when I delete the data from the temporary table it inserts the data to the production table. The issue it that when I delete the data records from the temporary table it only inserts the first record.

我可以保存已删除的数据记录中的选定记录吗?例如,我想将POST ='T'

Can I save selected records, from the deleted data records? For example I want to save to Production Table those records that in the field POST = 'T'

推荐答案

字段中的那些记录保存到生产表中简单的要求如下:

This should be a pretty simple requirement along the following lines

CREATE TRIGGER YourTrigger
ON Staging
AFTER DELETE 
AS
INSERT INTO Production
SELECT * 
FROM DELETED

但是 OUTPUT 子句可能比触发器更有效

But using the OUTPUT clause may well be more efficient than a trigger anyway

DELETE Staging 
OUTPUT DELETED.* 
INTO Production

这篇关于如何创建将删除的数据(多个记录)保存到生产表的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆