SQL Server: @@RowCount and Zero Count

The SQL Server system function @@rowcount is used to return the number of rows affected by the last executed statement. There are atleast three cases where @@rowcount will return the value 0. Let us explore these cases in this post.

Case 1: When used with select statement that does not return any rows

select 1 where 1=2
select @@rowcount

Case 2: When used with SET options (setting nocount on/off, datefirst values, etc)

set nocount off
select @@rowcount

Case 3: When used with USE satement which changes the current database name

use master
select @@rowcount

OUTPUT

sql-server-rowcount

No comments:

Post a Comment