问题
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
someXmlcolumn must adhere to the XML Schema Collection namedFooSchema. You can specify that the XML must be a document or that it can contain a fragment by including the appropriate keyword,DOCUMENTorCONTENT, respectively. If omitted, the default isCONTENT.
回答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