Ok I have a very simple mysql database but when i try to run this query via mysql-admin i get weird errors
好吧我有一个非常简单的mysql数据库,但当我尝试通过mysql-admin运行此查询时,我得到奇怪的错误
INSERT INTO customreports (study, type, mode, select, description) VALUES ('1', '2', '3', '4', '5');
INSERT INTO customreports(研究,类型,模式,选择,描述)VALUES('1','2','3','4','5');
Error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select, description) VALUES ('1', '2', '3', '4', '5')' at line 1
1064 - 您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在“选择,描述”附近使用正确的语法VALUES('1','2','3','4','5')'在第1行
7 个解决方案
#1
You're having problems because you're using SQL reserved words as column names and not escaping them. Try like this:
您遇到了问题,因为您使用SQL保留字作为列名而不是转义它们。试试这样:
INSERT INTO `customreports`
(`study`, `type`, `mode`, `select`, `description`)
VALUES
('1', '2', '3', '4', '5');
#2
Yeah, I would rewrite as:
是的,我会改写为:
INSERT INTO [customreports] ([study], [type], [mode], [select], [description]) VALUES ('1', '2', '3', '4', '5');
INSERT INTO [customreports]([study],[type],[mode],[select],[description])VALUES('1','2','3','4','5');
#3
just a guess, but is reserved word "select" (listed as a column name) causing a problem?
只是一个猜测,但保留字“选择”(列为列名)导致问题?
#4
"SELECT" is a reserved word in SQL... use a different word than "select"
“SELECT”是SQL中的保留字...使用与“select”不同的单词
#5
The word 'select' is reserved in sql. The interpreter thinks you're trying to use a SELECT statement inside the INSERT INTO statement. You need to enclose the field names so that the interpreter doesn't read them as commands.
'select'这个词在sql中保留。解释器认为您正在尝试在INSERT INTO语句中使用SELECT语句。您需要将字段名称括起来,以便解释器不会将它们作为命令读取。
Update for MySQL:
MySQL更新:
insert into customreports ('study','type','mode','select','description') values...
#6
Correct per Chaos... but the critical thing to remember is you should do your best to NOT use RESERVED words as column names in a table... such as SELECT and TYPE.... not positive of the other three, but that's where your conflict is. Yes, by being explicit with quotes around the fields will tell the SQL you mean the field within, but its also best to know WHY its failing, and not just a work-around resolution... helps prevent similar issues in the future.
正确的每个混乱...但要记住的关键是你应该尽量不要使用保留字作为表中的列名...例如SELECT和TYPE ....不是其他三个的正面,但那是你的冲突在哪里。是的,通过明确引用字段周围的引号将告诉SQL你的意思是其中的字段,但它也最好知道它为什么失败,而不仅仅是一个解决方案......有助于防止将来出现类似的问题。
#7
Ditto the above, but I believe you need double quotes around the column names, not single quotes. Perhaps some flavors of SQL will process the single quotes correctly, but I think the standard says double quotes for field names, single quotes for field values.
同上,但我相信你需要围绕列名称加双引号,而不是单引号。也许某些类型的SQL会正确处理单引号,但我认为该标准表示字段名称的双引号,字段值的单引号。
#1
You're having problems because you're using SQL reserved words as column names and not escaping them. Try like this:
您遇到了问题,因为您使用SQL保留字作为列名而不是转义它们。试试这样:
INSERT INTO `customreports`
(`study`, `type`, `mode`, `select`, `description`)
VALUES
('1', '2', '3', '4', '5');
#2
Yeah, I would rewrite as:
是的,我会改写为:
INSERT INTO [customreports] ([study], [type], [mode], [select], [description]) VALUES ('1', '2', '3', '4', '5');
INSERT INTO [customreports]([study],[type],[mode],[select],[description])VALUES('1','2','3','4','5');
#3
just a guess, but is reserved word "select" (listed as a column name) causing a problem?
只是一个猜测,但保留字“选择”(列为列名)导致问题?
#4
"SELECT" is a reserved word in SQL... use a different word than "select"
“SELECT”是SQL中的保留字...使用与“select”不同的单词
#5
The word 'select' is reserved in sql. The interpreter thinks you're trying to use a SELECT statement inside the INSERT INTO statement. You need to enclose the field names so that the interpreter doesn't read them as commands.
'select'这个词在sql中保留。解释器认为您正在尝试在INSERT INTO语句中使用SELECT语句。您需要将字段名称括起来,以便解释器不会将它们作为命令读取。
Update for MySQL:
MySQL更新:
insert into customreports ('study','type','mode','select','description') values...
#6
Correct per Chaos... but the critical thing to remember is you should do your best to NOT use RESERVED words as column names in a table... such as SELECT and TYPE.... not positive of the other three, but that's where your conflict is. Yes, by being explicit with quotes around the fields will tell the SQL you mean the field within, but its also best to know WHY its failing, and not just a work-around resolution... helps prevent similar issues in the future.
正确的每个混乱...但要记住的关键是你应该尽量不要使用保留字作为表中的列名...例如SELECT和TYPE ....不是其他三个的正面,但那是你的冲突在哪里。是的,通过明确引用字段周围的引号将告诉SQL你的意思是其中的字段,但它也最好知道它为什么失败,而不仅仅是一个解决方案......有助于防止将来出现类似的问题。
#7
Ditto the above, but I believe you need double quotes around the column names, not single quotes. Perhaps some flavors of SQL will process the single quotes correctly, but I think the standard says double quotes for field names, single quotes for field values.
同上,但我相信你需要围绕列名称加双引号,而不是单引号。也许某些类型的SQL会正确处理单引号,但我认为该标准表示字段名称的双引号,字段值的单引号。