表字段可以包含连字符吗? [英] Can a table field contain a hyphen?
问题描述
我在MySQL表中有一个表,其中有一个字段名'product',并且要将其重命名为'ds-product'。
I have a table in a MySQL table with a fieldname 'product', and want to rename it to 'ds-product'.
CMS类型系统am using使用formfields的id作为要插入的表字段的名称。
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 must make the table field name match.
但是,当试图做一个查询时,我得到的错误是
However, when trying to do a query I get the error that
'字段列表'中的未知列'sales.ds'
Unknown column 'sales.ds' in 'field list'
有任何方法,我可以有一个名为ds- ?
Is there any way I can have a field called ds-product?
推荐答案
是的,如果使用分隔符,您可以使用标点符号,空格,国际字符和SQL保留字标识符:
Yes, you can use punctuation, white space, international characters, and SQL reserved words if you use delimited identifiers:
SELECT * FROM `my-table`;
在MySQL中,使用back-ticks。在标准SQL中,使用双引号。
In MySQL, use the back-ticks. In standard SQL, use double-quotes.
或者如果您使用MySQL,您可以设置 ANSI_QUOTES
SQL模式:
Or if you use MySQL you can set the ANSI_QUOTES
SQL mode:
SET SQL_MODE = ANSI_QUOTES;
SELECT * FROM "my-table";
这篇关于表字段可以包含连字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!