开发者

Is there any reason to write a database column between square brackets?

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开发者_Go百科 top of the Database are developed either in C# or VB.NET.

Thanks


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.)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜