What are the advantages and disadvantages of turning NOCOUNT
off in SQL server queries?
I personally like to turn NOCOUNT on for queries that get run in an manual fashion and use a lot of Print
statements to output debugging messages. In this way, your output would look less like:
Updating usernames (287 rows updated) Done Updating passwords (287 rows updated) Done Doing the next thing (1127 rows updated) Done
And more like
Updating usernames Done Updating passwords Done Doing the next thing Done
Depending on the sensitivity of what you're updating, sometimes it is helpful to include the counts; however, for complex scripts with a lot of output I usually like to leave them out.
From SQL BOL:
SET NOCOUNT ON prevents the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. For stored procedures that contain several statements that do not return much actual data, setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is greatly reduced.
See http://msdn.microsoft.com/en-us/library/ms189837.aspx for more details.
Also, this article on SQLServerCentral is great on this subject:
Performance Effects of NOCOUNT
And it's not just the network traffic that is reduced. There is a boost internal to SQL Server because the execution plan can be optimized due to reduction of an extra query to figure out how many rows were affected.
SET NOCOUNT ON is an oneline Statement, Sql server sends message back to client.this is performed for Every Process(ie .. select,insert,update,delete).if you avoid this message we can improve overall performance for our Database and also reduce network traffic
For EX:
declare @a table(id int)
set nocount on
insert @a select 1 union select 2
set nocount off
Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results.
I always have it set to ON for the reasons above, but if you have more than 1 result set in your proc it could mess up client code