SET NO COUNT ON – Stored Procedures

For every statement in a stored procedure, SET NOCOUNT ON stops procedure outcome messages from being sent to the client. In other words, setting NOCOUNT to ON will make messages like “number of rows affected” ineffective.

This slideshow requires JavaScript.

Image Credits: Google.

As per the documentation, 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.

So, finally, how it is supposed to declare?
Here you go.

CREATE PROCEDURE uspGetOrdersInfo
AS
BEGIN
SET NOCOUNT ON

DELETE FROM tbOrders WHERE Status = ‘FAILED’
SELECT * FROM tbOrders WHERE Status = ‘PLACED’

GO;

EXEC uspGetOrdersInfo;

Hope you find this article helpful.

One comment

  1. Great explanation, it is very easy to understand. Thank you shafi. I am learning new things in SQL from your Blog. Please continue to post more n more. It is very useful for SQL lovers and can enjoy by knowing n gaining knowledge in SQL.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s