SET ANSI_WARNINGS OFF 的范围 [英] Scope of SET ANSI_WARNINGS OFF
问题描述
如果我在一个存储过程中有 SET ANSI_WARNINGS OFF
来消除警告,它只会对该存储过程产生影响,对其他存储过程没有影响,这意味着在其他存储过程中,ANSI_WARNINGS
仍在运行.如果我想为所有存储过程关闭它怎么办?为什么默认开启?我怎么知道?
if I have SET ANSI_WARNINGS OFF
in one stored procedure to get rid of a warning, it only takes effects of that stored procedure and has no impact on other ones, which means in other stored procedures, the ANSI_WARNINGS
is still on.
What if I want to turn it off for all stored procedures?
Why it is default on? How could I know that?
sql server 中的其他设置(例如,NOCOUNT
)是否也以同样的方式工作?
Do other settings(e.g., NOCOUNT
) in sql server work the same way?
非常感谢.
如果有人能与我分享有关这些设置的共同特征的文章,那就太好了.
It will be great if anybody can share articles about common characteristics of these settings with me.
推荐答案
可能值得指出的是,它不仅不会影响其他存储过程,它只会影响 SET 操作之后的语句
It's possibly worth point out that not only does it NOT affect other stored procedures, it only affects statements following the SET operation
例如运行此程序,您将看到该选项已关闭,然后打开,然后再次关闭.
e.g. run this and you will see that the option is turned off then on and then off again.
CREATE TABLE test
(
intvalue int NULL
)
INSERT INTO test VALUES (1)
INSERT INTO test VALUES (NULL)
SET ANSI_WARNINGS OFF
SELECT COUNT(intvalue) FROM test
-- (1 row(s) affected)
SET ANSI_WARNINGS ON
SELECT COUNT(intvalue) FROM test
-- (1 row(s) affected)
-- Warning: Null value is eliminated by an aggregate or other SET operation.
SET ANSI_WARNINGS OFF
SELECT COUNT(intvalue) FROM test
-- (1 row(s) affected)
DROP TABLE test
这篇关于SET ANSI_WARNINGS OFF 的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!