Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how to count number of deletion performed on table

Author  Topic 

msa969
Starting Member

13 Posts

Posted - 2002-02-23 : 14:45:03
How can I keep a count of the number of deletions that is performed on my dept table?

Assume we have a table deptt which has no primary key so thus we can have duplicate department number, for example the department 50 is entered more then 5 times.

ACCEPT p_number PROMPT 'Please enter department number: '

DECLARE

v_deptno dept.deptno%TYPE := &p_number;
v_number_of deletion NUMBER(20);
/* to count deletion*/
BEGIN

DELETE from dept
where deptno = v_deptno;
/* I want to be able to count the number of deletetions performed here*/
dbms_output.put_line(v_number_of deletion); /* want to print */

END;
/


robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-02-23 : 15:40:34
The code you provided is not Transact-SQL, so I can't say for sure if it can be done. However, if you are using T-SQL, the @@ROWCOUNT variable will contain the number of rows affected by the last SELECT, UPDATE, INSERT or DELETE operation. You could therefore get the count like this:

DELETE FROM dept WHERE deptno=v_deptno
SELECT @@ROWCOUNT


Go to Top of Page
   

- Advertisement -