表字段可以包含连字符吗? [英] Can a table field contain a hyphen?

查看:39
本文介绍了表字段可以包含连字符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 类型系统使用表单域的 id 作为要插入的表字段的名称.

The CMS type system I am using uses the id of formfields as the name of the table field to insert into.

对于大多数情况,这可以正常工作,但对于特定字段,它会在我提供的任何 ID 前面加上ds-",因此我必须使表字段名称匹配.

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-product 的字段吗?

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 中,使用反引号.在标准 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆