如何使用存储过程同时将删除的数据插入另一个表中 [英] how to insert the deleted data in another table simultaneously using stored procedure

查看:79
本文介绍了如何使用存储过程同时将删除的数据插入另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在采访中我被问到一个问题:



给出两个表我需要从一个表中删除数据并同时使用存储将其添加到另一个表中程序。



怎么做。

In the interview I was asked a question:

Two tables are given I need to delete a data from one table and simultaneously add it in another table using Stored Procedure.

How to do it.

推荐答案

这可以通过多种方式完成。一种方法是使用 OUTPUT子句 [ ^ ]并将删除的行放入表变量中,然后将其插入另一个表中。另一种可能性是利用删除的表 [ ^ ]触发器内。当然,删除前的一个简单的 INSERT INTO ... SELECT 结构也可以是一个选项。



但是,确切地说,这些都不是同时发生的。
This can be done in numerous ways. One way would be to use the OUTPUT clause[^] and get the deleted rows into a table variable and then insert that into another table. Another possibility would be to utilize deleted table[^] inside a trigger. Of course a simple INSERT INTO ... SELECT structure before the deletion could also be an option.

However, to be precise, none of these are simultaneous.


问题是具体的:'从一个表中删除数据并同时将其添加到另一个表中!只能通过存储过程!!!'。因此,您必须构建一个动态函数,该函数能够在多个表上执行一组操作(在更广泛的意义上,不仅是INSERT或DELETE)。



所以你必须使用SP,局部变量,交易;我的意思是一个动态的过程。按照链接和解决方案4,这将是有帮助的。这只是UPDATE的基本示例。你也可以包括INSERT和DELETE。

谢谢你。

如何在两个表中创建1列,如果我们改变一个,则自动另一个更改 [< a href =http://www.codeproject.com/Questions/877154/How-to-make-column-in-two-table-and-if-we-change-i?arn=42target =_ blank title =新窗口> ^ ]
The question was specific: 'delete a data from one table and simultaneously add it in another table !!! only through Stored Procedure !!!'. So you have to build a dynamic function which is able to conduct a set of operation (in a broader sense not only INSERT or DELETE) on multiple tables.

So you have to use SP, local variable, Transaction; I mean a dynamic process for this. Follow the link and "solution 4", it will be helpful. This is a basic example of UPDATE only. You can include INSERT and DELETE also.
Thank You.
How to make 1 column in two table and, if we change in one , another change automatically[^]


这篇关于如何使用存储过程同时将删除的数据插入另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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