Saturday, 7 May 2016

Use of NOCOUNT statement in SQL server ?

To stop the message that shows the no of rows affected by the SQL statement or stored Procedures,
we can use the NOCOUNT statement in T-SQL statement as well as in stored procedures.

Syntax

NOCOUNT ON | OFF

Example
Before using NOCOUNT Statement.



In the message tab it will show the no of rows affected by the above SQL statement.

After using NOCOUNT statement


After using the NOCOUNT statement the no of rows affected by the above SQL statement is not returned.

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

To improve the performance of the query we can use the NOCOUNT ON statement in SQL query.

Don't forget to OFF the NOCOUNT Statement at the end of the T-SQL statement. 

No comments:

Post a Comment