SQL Server 中的 ANSI_NULLS 标志? [英] ANSI_NULLS flag in SQL Server?
本文介绍了SQL Server 中的 ANSI_NULLS 标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以通过使用 SET ANSI_NULLS OFF
或 SET ANSI_NULLS ON
I can change the value of SET ANSI_NULLS
by using SET ANSI_NULLS OFF
or SET ANSI_NULLS ON
问题 #1 如何获得 当前 值?
问题 #2 设置值是否应用于查询?桌子?实例?整个数据库?
Question #2 does setting a value is applied to query? Table? Instance? Whole db?
问题 #3 如果我进入一家执行 if myNullParam <>null
的公司,我应该检查什么地方(db ? schema?查询?)告诉他们 - 这行得通,还是不行?
Question #3 If I'm entering a company which does if myNullParam <>null
, what is the place which I should check (db ? schema? query ?) to tell them - this gonna work , or Not ?
谢谢.
推荐答案
select databasepropertyex('MyDatabaseName', 'IsAnsiNullsEnabled')
会告诉你数据库的默认值.Hitesh 的回答会告诉您当前会话的价值.- 数据库有默认设置,每个会话都可以覆盖数据库默认设置.
- 会话值.但是,MSDN 文档说
要使脚本按预期工作,无论 ANSI_NULLS 数据库选项或 SET ANSI_NULLS 的设置如何,请在可能包含空值的比较中使用 IS NULL 和 IS NOT NULL.
所以虽然它可能有效,但它肯定违反了最佳实践.
select databasepropertyex('MyDatabaseName', 'IsAnsiNullsEnabled')
will tell you the database default. Hitesh's answer will tell you the value for the current session.- The database has a default settting, and each session can override the database default.
- The session value. However, the MSDN documentation says
For a script to work as intended, regardless of the ANSI_NULLS database option or the setting of SET ANSI_NULLS, use IS NULL and IS NOT NULL in comparisons that might contain null values.
So while it may work, it's certainly against best practices.
这篇关于SQL Server 中的 ANSI_NULLS 标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文