有什么理由在方括号之间写入数据库列吗?
我正在维护另一个人在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
括号(或其他数据库引擎中的其他标识符)只是告诉查询引擎该术语是数据库中对象的标识符的显式方式。常见原因包括:
(我认为也有可能存在非常轻微的性能改进,因为引擎不需要尝试识别该项目的含义,它已被明确告知它是一个对象。它仍然需要验证这一点,当然,但这可能对内部运作有一点帮助。)
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:
(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.
例如,如果您有一个字段是关键字,例如 [Date] 或 [Select] 或在本例中为 [desc]
For example if you have a field that is a keyword e.g [Date] or [Select] or in this case [desc]