July 21, 2011

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


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Madhivanan,an MSc computer Science graduate from Chennai-India, works as a works as a Lead Subject Matter Expert at a company that simplifies BIG data. He started his career as a developer working with Visual Basic 6.0, SQL Server 2000 and Crystal Report 8. As years went by, he started working more on writing queries in SQL Server. He now has good level of knowledge in SQLServer, Oracle, MySQL and PostgreSQL as well. He is also one of the leading posters at www.sqlteam.com and a moderator at www.sql-server-performance.com. His T-sql blog is at http://beyondrelational.com/blogs/madhivanan

 
  Feedback:

comments

0 Responses to "SQL Server: @@RowCount and Zero Count"
 

Copyright © 2009-2014 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions