有什么理由在方括号之间写入数据库列吗?

发布于 2024-12-06 21:37:38 字数 197 浏览 1 评论 0原文

我正在维护另一个人在 SQL Server 中创建的数据库。在一个表中,我发现一列的名称位于方括号之间。该字段的名称为 desc,它在表中存储为 [desc]。其他字段存储时不带方括号。这个选择背后有什么特殊的原因/惯例吗?

构建在数据库之上的应用程序是用 C# 或 VB.NET 开发的。

谢谢

I am maintaining a database created by another person in SQL Server. In one table I found a column whose name is between square brackets. The name of the field is desc and it is stored in the table as [desc]. The other fields are stored without square brackets. Is there any special reason/convention behind this choice?

The applications built on top of the Database are developed either in C# or VB.NET.

Thanks

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

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

发布评论

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

评论(3

黒涩兲箜 2024-12-13 21:37:38

括号(或其他数据库引擎中的其他标识符)只是告诉查询引擎该术语是数据库中对象的标识符的显式方式。常见原因包括:

  1. 包含空格的对象名称将无法作为查询的一部分进行解析,除非它们包含在方括号中。
  2. 作为保留字的对象名称可能无法解析(或者更糟糕的是,正确解析并执行意外的操作)。

(我认为也有可能存在非常轻微的性能改进,因为引擎不需要尝试识别该项目的含义,它已被明确告知它是一个对象。它仍然需要验证这一点,当然,但这可能对内部运作有一点帮助。)

The brackets (or other identifiers in other database engines) are just an explicit way of telling the query engine that this term is an identifier for an object in the database. Common reasons include:

  1. Object names which contain spaces would otherwise fail to parse as part of the query unless they're wrapped in brackets.
  2. Object names which are reserved words can fail to parse (or, worse, correctly parse and do unexpected things).

(I suppose it's also possible that there may be an ever-so-slight performance improvement since the engine doesn't need to try to identify what that item means, it's been explicitly told that it's an object. It still needs to validate that, of course, but it may be a small help in the inner workings.)

如果您的名称包含保留字(例如 SELECT)或空格,则需要用 [] 将名称括起来。

在您的示例中,您有 [desc],它是 DESCENDING 的缩写。

If your names contains either a reserved word (such as SELECT) or spaces, then you need to surround the name with [].

In your example, you have [desc], which is short for DESCENDING.

感受沵的脚步 2024-12-13 21:37:38

例如,如果您有一个字段是关键字,例如 [Date] 或 [Select] 或在本例中为 [desc]

For example if you have a field that is a keyword e.g [Date] or [Select] or in this case [desc]

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