Set NOCount On

来源:互联网 发布:淘宝退货率怎么算的 编辑:程序博客网 时间:2024/05/01 19:15

Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results.

停止返回指示一个T-SQL语句影响的行数的信息作为返回结果的一部分。

Syntax 语法

SET NOCOUNT { ON | OFF }

Remarks

备注: When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.

当 Set NoCount设为On时,显示T-SQL语句影响的行数的信息不被返回。当Set NoCount设为Off时,行数将被返回。

The @@ROWCOUNT function is updated even when SET NOCOUNT is ON. 当Set NoCount设为On时,@@RowCount函数也会更新。

SET NOCOUNT ON eliminates the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. When using the utilities provided with Microsoft® SQL Server™ to execute queries, the results prevent "nn rows affected" from being displayed at the end Transact-SQL statements such as SELECT, INSERT, UPDATE, and DELETE.

Set NoCount On去除了在一个存储过程中每个语句的Done_In_Proc消息传递给客户的过程。当使用由Microsoft® SQL Server™提供的实用工具执行查询时,执行结果防止了“n 行 受到了影响”在一个如Select,Insert,Update,Delete的T-SQL语句结束时显示。

For stored procedures that contain several statements that do not return much actual data, this can provide a significant performance boost because network traffic is greatly reduced.

对于包含了很多不返回实际数据的语句的存储过程,使用Set NoCount on可以很大的提高性能,因为网络流量可以大幅减少。

The setting of SET NOCOUNT is set at execute or run time and not at parse time.

Set OnCount是在执行时设置而不是在分析阶段。

结论:当没有必要返回给客户端“n 行受到影响”消息时,应该在存储过程的开始设置 SET NOCOUNT ON,在存储过程结束时设置SET NOCOUNT OFF.

如果未关闭,则下次hibernate 等持久化时会报错!

(纯属个人总结,呵呵,自己学习)

0 0
原创粉丝点击