@@ROWCOUNT with SET NOCOUNT ON in SQL Server

By default the value of SET NOCOUNT is OFF in SQL Server, and for each SELECT, INSERT, UPDATE, and DELETE statement inside the stored procedure a message with the number of affected rows by that statement is returned.

SELECT Column1, Column2, Column3 FROM dbo.test_table

SET NOCOUNT ON will stop the message with the number of affected rows from being returned as part of the results.

SET NOCOUNT ON;
SELECT Column1, Column2, Column3 FROM dbo.test_table

@@ROWCOUNT returns the number of rows affected by the last statement, and is updated even when SET NOCOUNT is ON.

SET NOCOUNT ON;
SELECT Column1, Column2, Column3 FROM dbo.test_table
SELECT @@ROWCOUNT

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">