Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
BRH 6
Index 6
Non-Clustered Index 5
Performance 4
#SQLServer 3
#TSQL 2
SQLServer 2
Clustered Index 2
Filtered Index 2
SSMS 2

Archive · View All
April 2010 7
March 2010 4
August 2010 2
May 2010 2
October 2011 1
September 2010 1

SET NOCOUNT ON

Apr 9 2010 1:17PM by Dinesh Asanka   

This is a setting that DBA are advised to place at the start of the stored procedure.

What this setting does?

Let us run an sample code for this.

USE AdventureWorks
GO
SELECT * FROM Person.Address

SET NOCOUNT ON

SELECT * FROM Person.Address

SET NOCOUNT OFF

You will that first select query (at line no 3), will execute with out the the above setting while second SELECT statement (at line no 7) will execute with the SET NOCOUNT ON setting.

Though both queries will result same output. So what is the different.

If you got the message tab, you will see following output there.

image

Only first query has returned the number of rows effected not the second query.

This is what BOL says,

“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, or for procedures that contain Transact-SQL loops, setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is greatly reduced.”

In simple term, SET NOCOUNT ON will not return number of records affected to the client. What is the bug deal. If you are not using this information, it is an unnecessary burden to your server and network. By not returning this information, you are using less resources. This might not be huge saving, but might be the string which will brake the back of the camel.

How to Implement

It is advisable to implement  this in each stored proc as follows.

CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> 
	-- Add the parameters for the stored procedure here
	<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>, 
	<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
	SET NOCOUNT OFF;
END
GO

Make sure you SET NOCOUNT to OFF at the end of the stored proc.

Following query will list you all the stored procedures which does not have SET NOCOUNT ON statement.

SELECT DISTINCT
        OBJECT_NAME(id)
FROM    syscomments c
        INNER JOIN sys.objects o ON c.id = o.object_id
WHERE   text NOT LIKE '%SET NOCOUNT ON%'
        AND type = 'P'
        AND id NOT IN ( SELECT  id
                        FROM    syscomments c
                                INNER JOIN sys.objects o ON c.id = o.object_id
                        WHERE   text LIKE '%SET NOCOUNT ON%'
                                AND type = 'P' )

Tags: Performance,


Dinesh Asanka
116 · 1% · 444
1
 
0
Lifesaver
 
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"SET NOCOUNT ON" rated 5 out of 5 by 1 readers
SET NOCOUNT ON , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]