列名中的保留字 - 插入 MySQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9800075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:38:58  来源:igfitidea点击:

Reserved word in column name - insert into MySQL

mysqlinsertreserved-words

提问by krYsti

I have a MySQL database with the word "group" in one of the column names. I can't change this database and column's name; it's not mine.

我有一个 MySQL 数据库,group其中一个列名中带有“ ”一词。我无法更改此数据库和列的名称;不是我的。

Table users, columns: id, name, password, group,and other. I need to insert a record into this table. I tried INSERT INTO users (name, group) VALUES ('John', '9'), but it's not working because of "group".

表用户、列:id, name, password, group,等。我需要在这个表中插入一条记录。我试过了INSERT INTO users (name, group) VALUES ('John', '9'),但由于“ group”而无法正常工作。

Can you help me, how to insert a record into this table, please?

你能帮我,如何在这张表中插入一条记录,好吗?

回答by sikander

Try:

尝试:

INSERT INTO users (`name`, `group`) VALUES ('John', '9')

回答by sikander

use backticks(`) around column names when you use reserved keywords in query:

在查询中使用保留关键字时,在列名周围使用反引号(`):

INSERT INTO users (`name`,`group`) VALUES ('John', '9')

Read here: Reserved Words

在这里阅读: 保留字