MySQL INSERT 查询是否会乱序运行

发布于 2024-12-05 08:55:35 字数 820 浏览 1 评论 0原文

我正在尝试运行:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝對不後悔。 2024-12-12 08:55:35

只要 id 是列名 - 您需要删除单引号并将其替换为反引号

INSERT INTO orders (`id`, `datetime`, ...

此外,您也可以删除反引号并按原样指定 id ,但这可以如果你的列名与 mysql 的关键字之一同名,例如 from

UPD:正如有人在评论中指出的那样(抱歉,我不记得你的名字了,评论已被已删除) - 如果id 是一个自动增量字段,那么您可以完全避免指定它(如果是这样 - 不要忘记从值列表中删除它的值(空字符串))

As long as id is a column name - you need to remove single quotes and replace them with backticks

INSERT INTO orders (`id`, `datetime`, ...

Also 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 as from

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文