SET NOCOUNT

SET NOCOUNT#

Stops the message that shows the count of the number of rows affected by a Transact-SQL statement from being sent to the client after each statement.

Syntax#

SET NOCOUNT { ON | OFF }  [;]

Remarks#

SET NOCOUNT ON suppresses the rows-affected count that Querona otherwise sends after every SELECT and data-modification statement — the message ExecuteNonQuery() / SqlDataReader.RecordsAffected read on the client, and that SSMS renders as “(N rows affected)”. SET NOCOUNT OFF restores the default, where the count is sent.

SET NOCOUNT only affects that wire-level message. It has no effect on @@ROWCOUNT or ROWCOUNT_BIG, which keep reporting the true row count regardless of the NOCOUNT setting.

The setting is scoped to the session and takes effect for statements executed after it, until it is changed again or the session ends.

Permissions#

Requires membership in the public role.

Examples#

SET NOCOUNT ON;
DELETE FROM dbo.Log WHERE LogDate < '2020-01-01';   -- no "(N rows affected)" message
SELECT @@ROWCOUNT;                                  -- still reports the true count

SET NOCOUNT OFF;
DELETE FROM dbo.Log WHERE LogDate < '2020-01-01';   -- "(N rows affected)" message returns

See Also#