What are the advantages and disadvantages of turning NOCOUNT off in SQL Server queries?
views:
580answers:
6From 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.
It simply stops the message that shows the # of rows effected for being sent/displayed, which provides a performance benefit, especially if you have many statements that will return the message. It improves performance since less data is being sent over the network (between the sql server and front end).
More at BOL: SET NOCOUNT
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
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.
compare and contrast the major differences between the milling and turning processes with regard to work holding, material removal and machine tool design.