Tuesday 29 May 2012

SET NOCOUNT in SQL SERVER


When SET NOCOUNT is ON, the count is not returned. When SET NOCOUNT is OFF, the count is returned.

The
@@ROWCOUNT function is updated even when SET NOCOUNT is ON.
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.

The setting specified by SET NOCOUNT is in effect at execute or run time and not at parse time.

e.g

When

SET NOCOUNT ON
SELECT
TOP 10 * FROM Product_Master
SELECT @@ROWCOUNT
Then message will display like:
Command(s) completed successfully.
--------------------------------------
When

SET NOCOUNT OFF
SELECT TOP 10 * FROM Product_Master
SELECT @@ROWCOUNT
Then message will display like :
(10 row(s) affected)

(1 row(s) affected)

No comments:

Post a Comment