Reserved word in column name - insert into MySQL [duplicate]

感情迁移 提交于 2019-11-26 16:50:06

问题


This question already has an answer here:

  • Syntax error due to using a reserved word as a table or column name in MySQL 1 answer

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.

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".

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


回答1:


Try:

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



回答2:


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

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

Read here: Reserved Words



来源:https://stackoverflow.com/questions/9800075/reserved-word-in-column-name-insert-into-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!