Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.
Posted 14-Feb-13 4:21am
Edited 14-Feb-13 5:35am
v2
Comments
Sandeep Mewara at 14-Feb-13 9:40am
   
how to calculate the records which have deleted from table
Are you maintaining any record of deletion? If not, you cannot.
ryanb31 at 14-Feb-13 9:53am
   
What do you mean calculate the records which are deleted? Do you mean get a count when you do the delete? Please explain more.
Chris Reynolds (BNY) at 14-Feb-13 10:00am
   
Sounds like you need a trigger. There are plenty of examples around on the web. If you tell us what you want to do when a record is deleted we can offer more specific help.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100