为什么 SQL Server Management Studio 使用方括号生成代码?
生成代码/脚本时,
为什么 SQL Server Management Studio 使用方括号而不是双引号生成代码?
SELECT [NAME] FROM [TABLE]
有没有办法(设置/注册表项)将其配置为使用双引号(标准)?
从“TABLE”中选择“NAME”
这是非常 MSFT 风格的功能,因为他们的所有文档现在都指示双引号(请参阅 这个)
When generating code/scripts,
why does SQL Server Management Studio generate code using square brackets and not double-quotes?
SELECT [NAME] FROM [TABLE]
and is there a way (setting/registry entry) to configure it to use double-quotes (the standard) instead?
SELECT "NAME" FROM "TABLE"
This is very MSFT-ty feature, given that all their documentation now indicate the double-quotes (see this)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
处理保留字或包含空格的名称。
方括号是封装标识符的原生方式。它们是不对称的并且可以不匹配,而引号是对称的并且应该匹配(或加倍以将它们包含在名称中):
To cope with the names that are reserved words or contain whitespaces.
Square brackets are the native way to wrap the identifiers to. They are asymmetrical and can be unmatched, while the quotes are symmetrical and should be matched (or doubled to include them into the name):
您的链接至少对我来说解释了原因。括号不依赖于设置,但 " 的有效性取决于 QUOTED_IDENTIFIER 设置。
Your link explains why, at least to me. The brackets are not setting-dependant, but the validity of " depends on the QUOTED_IDENTIFIER setting.
要回答问题的另一半,SQL Server Management Studio 中有一个解决方法,使用“全部替换”命令 (Ctrl+H):
[ \[\]]
"
请记住,这也将替换评论中出现的括号。
To answer the other half of your question, there is a workaround in SQL Server Management Studio with the Replace All command (Ctrl+H):
[\[\]]
"
Have in mind that this will also replace occurrences of brackets in your comment.