問題描述
我有很多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"嗎?需要在存儲過程中嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!