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"吗?需要在存储过程中吗?
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
