阻止 SQL Server Management Studio 添加 ANSI_NULLS 和 QUOTED_IDENTIFIER

发布于 2024-12-20 05:42:57 字数 477 浏览 2 评论 0原文

当我右键单击/修改时,如何防止 SQL Management Studio (10.50.2500.0) 将其添加到每个存储过程的开头?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

这些设置对我来说都没有用。我的所有服务器、数据库和连接都设置了 ANSI_NULLS ON 和 QUOTED_IDENTIFIER ON。除此之外,我从不使用双引号(我使用括号表示保留字),并且所有可为空的字段在需要时我都会正确使用 IS NULL。

每次编辑程序时我都会删除设置。我的所有程序都已正确设置,并且在我的环境中永远不会改变。验证人:

SELECT uses_ansi_nulls, uses_quoted_identifier
FROM sys.sql_modules
WHERE object_id = object_id( 'proc_name' )

How do I prevent SQL Management Studio (10.50.2500.0) from adding this to the beginning of every stored procedure when I right-click/Modify?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

Neither of these settings are useful to me. ANSI_NULLS ON and QUOTED_IDENTIFIER ON is set on all my servers, DBs and connections I make. Besides that, I never use double quotes (I used brackets for reserved words) and all my nullable fields I properly use IS NULL when needed.

I delete the settings every time I edit a procedure. All my procedures properly have them set and that will never change in my environment. Verified by:

SELECT uses_ansi_nulls, uses_quoted_identifier
FROM sys.sql_modules
WHERE object_id = object_id( 'proc_name' )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沦落红尘 2024-12-27 05:42:57

不确定这算作答案还是无用的非答案,但正如 Damien_The_Un believeer 建议的那样您绝对不希望 SSMS 停止编写这些行的脚本。因为它们位于 sql_modules 表中,所以它们与 SQL 代码本身一起构成存储过程定义的组成部分。因此它们不能像 SQL 代码一样被“关闭”。

如果您从具有与创建/定义存储过程时使用的 ANSI_NULLS 选项值不同的连接创建/更改存储过程,则您会更改该存储过程的行为< /em>,永久!

正是由于这个原因,SSMS(以及任何半像样的 SQL 对象脚本工具)将总是输出这些行 - 因为如果您删除它们或更改它们,您将更改存储过程的定义(删除它们尤其不好,因为这意味着存储过程的行为可能会有所不同,具体取决于它发布的连接。

在谷歌上快速搜索“ANSI_NULLS QUOTED_IDENTIFIER存储过程”,最上面的结果是以下文章,它似乎非常清楚地解释了这些选项及其影响:http://ranjithk.com/2010/01/10/understanding-set-quoted_identifier-onoff/< /a>

Not sure whether this counts as an answer or an unhelpful non-answer, but as Damien_The_Unbeliever suggested you absolutely don't want SSMS to stop scripting these lines. Because they are in the sql_modules table they form an integral part of the definition of the stored procedure, along with the SQL code itself. So they can't be "turned off" any more than your SQL code could.

If you create/alter a stored procedure from a connection that has a different ANSI_NULLS option value to that used when the stored procedure was created/defined, then you change the behaviour of that stored procedure, permanently!

It is for this reason that SSMS (and any half-decent SQL object scripting tool) will always output these lines - because if you remove them or change them, you are changing the definition of the stored procedure (removing them, particularly, is bad because it means that the behaviour of the stored procedure, depending on what connection it is published from, can vary).

Doing a quick google search for "ANSI_NULLS QUOTED_IDENTIFIER stored procedure", the top result is the following article that seems to explain the options, and their impact, very clearly: http://ranjithk.com/2010/01/10/understanding-set-quoted_identifier-onoff/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文