MySQL INSERT 查询是否会乱序运行
我正在尝试运行:
INSERT INTO orders ('id','datetime','server','price','comment','addons','table_number','Omelet','Pancakes','Crepes','Salad','Steak_Sandwich','Chicken_Quesadilla','BLT','Prime_Rib','Pineapple_Upside_Down_Cake') VALUES ('','18/9/11 6:49:03PM','admin','0', 'N/A','None','0','1','2','3','4','5','6','7','8','9')
phpmyadmin 列标题看起来像:
id datetime server price comment addons table_number Omelet Steak_Sandwich Chicken_Quesadilla BLT Salad Prime_Rib Crepes Pancakes Pineapple_Upside_Down_Cake
并返回:
1064 - 您的 SQL 语法有错误;检查手册 与您的 MySQL 服务器版本相对应,以便使用正确的语法 靠近 ''id','日期时间','服务器','价格','评论','插件','table_number','Omelet','Pan' 在第 1 行
我可以像我那样乱序执行此操作吗?如果可以,任何人都可以发现我的错误 提前致谢
I am attempting to run:
INSERT INTO orders ('id','datetime','server','price','comment','addons','table_number','Omelet','Pancakes','Crepes','Salad','Steak_Sandwich','Chicken_Quesadilla','BLT','Prime_Rib','Pineapple_Upside_Down_Cake') VALUES ('','18/9/11 6:49:03PM','admin','0', 'N/A','None','0','1','2','3','4','5','6','7','8','9')
and phpmyadmin columheaders look like:
id datetime server price comment addons table_number Omelet Steak_Sandwich Chicken_Quesadilla BLT Salad Prime_Rib Crepes Pancakes Pineapple_Upside_Down_Cake
and is returning:
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
''id','datetime','server','price','comment','addons','table_number','Omelet','Pan'
at line 1
Can I do this out of order like I have it and if so can anyone spot my error
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要
id
是列名 - 您需要删除单引号并将其替换为反引号此外,您也可以删除反引号并按原样指定
id
,但这可以如果你的列名与 mysql 的关键字之一同名,例如from
UPD:正如有人在评论中指出的那样(抱歉,我不记得你的名字了,评论已被已删除) - 如果
id
是一个自动增量字段,那么您可以完全避免指定它(如果是这样 - 不要忘记从值列表中删除它的值(空字符串))As long as
id
is a column name - you need to remove single quotes and replace them with backticksAlso you can remove backticks too and specify
id
as-is, but this can cause an issue if your column name has the same name as one of mysql's keywords, such asfrom
UPD: As someone pointed in the comments (sorry, I don't remember your name and the comment has been already deleted) - if
id
is an autoincrement field, then you can avoid specifying it at all (if so - don't forget to remove its value (empty string) from values list too)