首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQL在所有查询中将noCount设置为on

SQL在所有查询中将noCount设置为on
EN

Stack Overflow用户
提问于 2014-01-17 14:44:19
回答 1查看 241关注 0票数 0

我有一个存储的程序,如下所示:

代码语言:javascript
复制
@userInput int

as
declare isSuperUser int
declare IDs table(
recordID int
);

set isSuper = select isSuper from [User]
if(@isSuper = 1)
Begin
    insert into recordID select * from TableA
End
else
Begin
    insert into recordID select * from TableB
End

select * from recordID

我想在每个查询中添加"set noCount on“,所以问题是:存储procedureA中的性能是否等同于存储procedureB?

商店procedureA:

代码语言:javascript
复制
@userInput int

as
declare isSuperUser int
declare IDs table(
recordID int
);
set noCount on
set isSuper = select isSuper from [User]
if(@isSuper = 1)
Begin
    insert into recordID select * from TableA
End
else
Begin
    insert into recordID select * from TableB
End

select * from recordID
set noCount off

商店procedureB:

代码语言:javascript
复制
@userInput int

as
declare isSuperUser int
declare IDs table(
recordID int
);
set noCount on
set isSuper = select isSuper from [User]
set noCount off
if(@isSuper = 1)
Begin
    set noCount on
    insert into recordID select * from TableA
    set noCount off
End
else
Begin
    set noCount on
    insert into recordID select * from TableB
    set noCount off
End
set noCount on
select * from recordID
set noCount off
EN

回答 1

Stack Overflow用户

发布于 2014-01-17 15:21:21

SET NOCOUNT ON可防止为存储过程中的每个语句向客户端发送DONE_IN_PROC消息。对于包含多个不返回太多实际数据的语句的存储过程,或者对于包含Transact-SQL循环的过程,将SET NOCOUNT设置为ON可以显著提高性能,因为网络通信量大大减少。

TechNet

当storedProcedure正在执行时,没有将数据发送回客户端的意义,设置noCount On可以提高性能,因为它减少了网络流量。在您的存储过程B中,您正在将NoCount on切换到off,这会增加网络流量。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21179497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档