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 类型系统使用表单域的 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";
这篇关于表字段可以包含连字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:表字段可以包含连字符吗?


基础教程推荐
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01