Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Posts
    195
    Thanks
    3
    Thanked 11 Times in 11 Posts

    DELETEd rows count

    Hi. How can I get the amount of rows deleted by a DELETE statement in SQL? I need to print the count on my page (I am using ColdFusion). Thanks.
    -MacWiz1220
    Science fiction does not remain fiction for long. And certainly not on the Internet.
    -Vinton Cerf: Chief Internet Evangelist for Google and co-creator of the TCP/IP Internet Protocol Suite

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Check your ColdFusion docs. It's probably got something builtin.

    For example, in ASP coding, you can do
    Code:
         connection.Execute "...sql code...", howmany
    and upon completion the variable howmany contains a count of the number of records affected (deleted or updated or inserted, as the case may be for the sql used).

    Similar constructs are available with JSP.

    So I'd be surprised if CF doesn't have a "built-in" way so that you don't have to pull trickery to find out.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I poked around in the CF docs and didn't see anything except RecordCount. One would *HOPE* that CF would use that to return the count of records deleted, but maybe not. CF is pretty old technology and it doesn't seem to have tried to catch up with other server side systems.

    So...

    Worst come to worst, I would think you could write a stored procedure that would do the delete and then do a SELECT NNN to return a recordset with just one record and once column, that being the count of deleted records.

    You could easily do that in SQL Server or MySQL, though the syntax in each is completely different. So what DB are you using?


  •  

    Posting Permissions

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