如何计算从表中删除的记录 [英] How to calculate records which were deleted from table

查看:85
本文介绍了如何计算从表中删除的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人告诉您如何计算从表中删除的记录。请帮我在存储过程中执行此操作。我想知道的另一件事是,我是否必须使用触发器?我不知道正确的方法和解决方案,请帮我解决这个问题。

解决方案

通常,没有一个正确的解决方案,但其中一个它可以实现的方式是一个触发器。 MSSQL中的触发器可以访问分别以 @inserted @deleted 引用的插入和删除记录。



因此,正确地提到 Chris Reynolds(BNY),其中一个选项可能是触发器,可能会调用特定的传递这些记录的存储过程。



此类触发器的一个示例可以在下面的链接中找到



http://social.msdn.microsoft.com/Forums / en / transactsql / thread / e883cdbc-3b17-430e-823b-02ba800cffc9 [ ^ ]



@deleted @inserted in trigger on的一般信息msdn



http://msdn.microsoft .CO m / en-us / library / ms191300.aspx [ ^ ]


在您的存储过程中声明一个变量,如:

  DECLARE   @ numberofrowsdeleted   INT  



使用它像:

  DELETE   FROM  YourTable  WHERE  conditionIsTrue 
SET @numberofrowsdeleted = @@ ROWCOUNT



@numberofrowsdeleted会给你删除的号码行。


Please someone tell how to calculate the records that have been deleted from a table. Please help me to do this in a stored procedure. One more thing I want to know is if I have to use trigger for that? I don''t know the correct way and solution, please help me to solve this problem.

解决方案

As usually, there is no single correct solution, but one of the ways it could be achieved is a trigger. Trigger in a MSSQL has an access to inserted and deleted records referenced as @inserted and @deleted respectively.

Thus, as correctly mentions Chris Reynolds (BNY), one of the options could be the trigger which might call a specific stored procedure passing these records.

One of examples for such trigger could be found on a link below

http://social.msdn.microsoft.com/Forums/en/transactsql/thread/e883cdbc-3b17-430e-823b-02ba800cffc9[^]

General info on @deleted @inserted in triggers on msdn

http://msdn.microsoft.com/en-us/library/ms191300.aspx[^]


declare a variable in your stored procedure like:

DECLARE @numberofrowsdeleted INT


use it like:

DELETE FROM YourTable WHERE conditionIsTrue
SET @numberofrowsdeleted = @@ROWCOUNT 


@numberofrowsdeleted will give you the number of deleted rows.


这篇关于如何计算从表中删除的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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