Tuesday, July 20, 2010

SET NOCOUNT ON, the performance booster

We normally use SET NOCOUNT ON in STORED PROCEDURES and TRIGGERS
What does actually SET NOCOUNT ON do?

When we normally execute a T-SQL statements (INSERT, UPDATE, SELECT, DELETE) in a query window, we see messages that says something like "(20 row(s) affected)" as the response to our query?

Database's internal architecture processes and displays the status of the execution process. The message display is done by the DONE_IN_PROC which is predefined in the architecture. Though this is default to SQL Server, this makes a slight difference in performance. Obviously, when a query has lots of T-SQL statements in it to perform, this costs you a lot.

The DONE_IN_PROC message is pretty useful when we are using the query window to execute the procedure. But it runs unwanted when the web applications are concerned. Each operation of T-SQL statement will return this internal message (eg, an INSERT, UPDATE, or SET in a WHILE loop) for each step within the Stored Procedure execution cycle.

So from the web developer perspective, its quite unwanted when he update the files in to production server. Lets have a boost in performance this way.

No comments: