Can a table field contain a hyphen?
I have a table in a MySQL table with a fieldname 'product', and want to rename it to 'ds-product'.
The CMS type system I am using uses the id of formfields as the name of the table field to insert into.
For most this works fine, but for a particular field it prepends 'ds-' to whatever ID I give it, so I 开发者_如何学JAVAmust make the table field name match.
However, when trying to do a query I get the error that
Unknown column 'sales.ds' in 'field list'
Is there any way I can have a field called ds-product?
Yes, you can use punctuation, white space, international characters, and SQL reserved words if you use delimited identifiers:
SELECT * FROM `my-table`;
In MySQL, use the back-ticks. In standard SQL, use double-quotes.
Or if you use MySQL you can set the ANSI_QUOTES
SQL mode:
SET SQL_MODE = ANSI_QUOTES;
SELECT * FROM "my-table";
Try putting brackets on the last part of your call on the table. in your case:
SELECT * FROM [TABLE-NAME];
just make sure to put the brackets on the table name only. not on the whole database it is located
SELECT * FROM some_database.anotherdatabase.[your-table];
P.S. works on columns, too.
I'm using Microsoft SQL Server Management.
精彩评论