Sql Server 2005 Puts square brackets around column name

谁说我不能喝 提交于 2019-12-23 12:49:51

问题


I have recently moved a database from Sql Server 2000 to Sql Server 2005. In the table designer, it insists on putting square brackets around a column named "Content" I don't see Content on the list of reserved words for Sql Server, so I don't understand why it is doing this. Is there a way I can prevent it?


回答1:


CONTENT is a keyword when defining an XML column with a schema.

See here.

Edit: The MSDN link is broken (per Champ's comment), so here is the relevant extract:

Creating a typed XML column is as simple as adding the name of the schema inside parentheses, as you see here:

CREATE TABLE Foo(FooID INT, someXml XML(CONTENT FooSchema))

This statement indicates that the someXml column must adhere to the XML Schema Collection named FooSchema. You can specify that the XML must be a document or that it can contain a fragment by including the appropriate keyword, DOCUMENT or CONTENT, respectively. If omitted, the default is CONTENT.




回答2:


The problem is that the field has the same name as the table. Sql Server 2000 did not seem to care about this potential ambiguity, but Sql Server 2005 does. When I add a field named Content to a table that is not named Content, the square brackets do not appear.

pamela




回答3:


No, you can't prevent it. You can always add square brackets around a column name so it doesn't hurt anything.



来源:https://stackoverflow.com/questions/1379913/sql-server-2005-puts-square-brackets-around-column-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!