Is quot;SET NOCOUNT OFFquot; necessary in a stored procedure?(是“SET NOCOUNT OFF吗?需要在存储过程中吗?)
问题描述
我有很多set nocount on
的程序.
是否需要在存储过程结束时将其关闭?
Is it necessary to turn it off at the end of stored procedure?
例如:
create procedure DummyProc
as
begin
set nocount on
...
set nocount off
end
推荐答案
set nocount on
将禁用 X 行受影响.
消息 SQL 返回.在某些情况下,由于客户端执行存储过程的不良影响,此消息被抑制.
set nocount on
will disable the X rows affected.
message SQL returns. This message is suppressed, in some cases, due to undesired effects with the client executing the stored proc.
set nocount off
将取消此抑制.但是,set nocount on
是一个范围设置,默认情况下,无论如何离开范围时都会关闭.
set nocount off
will undo this suppression. However, set nocount on
is a scope setting, and by default, will be turned off when leaving the scope anyway.
现在,是否需要set nocount off
?不,因为执行的任何新命令都将在不同的范围内,并且默认情况下 set nocount off
始终有效.但正如上面评论中所述,这被认为是一种很好的做法,只是明确表明该设置将在 proc 执行完成后恢复正常.
Now, is set nocount off
necessary? No, as any new commands executed will be in a different scope, and by default set nocount off
is always in effect. But as stated above in comments, it's considered a good practice, just to explicitly indicate that this setting will return to normal when the proc is finished executing.
这篇关于是“SET NOCOUNT OFF"吗?需要在存储过程中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是“SET NOCOUNT OFF"吗?需要在存储过程中吗?


- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01