Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    61

    Unanswered: Get Number of rows Deleted

    How do we get the number of rows deleted from a table?

    @@rowcount is returning 0

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    @@rowcount returns the number of rows affected by the last successful statement executed by your spid. It only has meaning for the duration of one statment, then it is reset.

    See the code for the gory details of how you can go worng
    Code:
    DECLARE @i1	INT
    ,  @i2		INT
    
    CREATE TABLE #foo (
       fooID	INT		NOT NULL
       )
    
    INSERT INTO #foo (fooID)
       SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION
       SELECT 3 UNION SELECT 4 UNION SELECT 5
    
    SELECT * FROM #foo
    
    DELETE FROM #foo WHERE 1 = fooID % 2
    
    SELECT @i1 = @@rowcount
    
    DELETE FROM #foo
    
    PRINT 'We''re working on it!'
    
    SELECT @i2 = @@rowcount
    
    SELECT @i1, @i2
    
    SELECT * FROM #foo
    
    DROP TABLE #foo
    -PatP

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    A true gentleman

    Isn't that a fubar table?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •