Click here to Skip to main content
13,288,520 members (59,311 online)
Rate this:
Please Sign up or sign in to vote.
See more: , +
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
Updated 14-Feb-13 5:35am
Sandeep Mewara 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 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) 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
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[^]

General info on @deleted @inserted in triggers on msdn[^]
Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2017
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