Counting the number of deleted rows in a SQL Server stored procedure

前端 未结 7 1721
借酒劲吻你
借酒劲吻你 2021-02-06 20:26

In SQL Server 2005, is there a way of deleting rows and being told how many were actually deleted?

I could do a select count(*) with the s

7条回答
  •  臣服心动
    2021-02-06 21:19

    In your example @@ROWCOUNT should work - it's a proper way to find out a number of deleted rows. If you're trying to delete something from your application then you'll need to use SET NOCOUNT ON

    According to MSDN @@ROWCOUNT function is updated even when SET NOCOUNT is ON as SET NOCOUNT only affects the message you get after the the execution.

    So if you're trying to work with the results of @@ROWCOUNT from, for example, ADO.NET then SET NOCOUNT ON should definitely help.

提交回复
热议问题