SET NOCOUNT ON effect

In stored procedures, SET NOCOUNT ON is often used;

Role: Prevent the row count information affected by the T-SQL statement or usp from being returned in the result set.

When SET ONCOUNT ON, does not return the count, when SET NOCOUNT OFF, returns the count;

Update @@RowCount even when SET NOCOUNT ON;

When SET NOCOUNT is on, the DONE_IN_proc message of each statement of the stored procedure will not be sent to the client. If the stored procedure contains some statements that do not return actual data, the network traffic will be greatly reduced, which can significantly improve application performance;

The setting specified by SET NOCOUNT takes effect at execution or runtime, but not at analysis time. Default: OFF

When SET NOCOUNT is ON, DONE_IN_PROC information for each statement in the stored procedure will not be sent to the client. When executing a query using the utilities provided by Microsoft SQL Server, "nn rows affected" will not appear in the query results at the end of Transact-SQL statements such as SELECT, INSERT, UPDATE, and DELETE. 

If the stored procedure contains some statements that do not return much actual data, this setting can significantly improve performance by reducing network traffic considerably. 

The SET NOCOUNT setting is set at execution or runtime, not at parse time. 

Permissions:

The SET NOCOUNT privilege defaults to all users. 

Conclusion: We should add SET NOCOUNT ON to the head of the stored procedure, and add SET NOCOUNT OFF when exiting the stored procedure to achieve the purpose of optimizing the stored procedure. 

There is another saying:

The foreground is generally a return as a result set, no matter whether the return is a result set or the feedback information of an operation. 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326483083&siteId=291194637