2

所以我一直在这个sql错误上停留了一段时间。

这是我正在使用的 SQL 行:

INSERT INTO images (image_name, orientation, restored, commercial, automotive, bespoke, before, after, date_added) 
VALUES ('image4-after.jpg', 'portrait', '1', '1', '1', '1', '24', '5', '2012-07-08')

使用这种结构:

image_id - int(11) AUTO_INCREMENT
image_name - varchar(40)
orientation - varchar(4)
restored - tinyint(1)
commercial - tinyint(1)
automotive - tinyint(1)
bespoke - tinyint(1)
before - int(11)
after - int(11)
date_added - date

收到错误消息:

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在“之前、之后、添加日期”附近使用的正确语法 VALUES ('image4-after.jpg'、'portrait'、'1'、'1'、'1''在第 1 行

谁能告诉我我做错了什么?

谢谢

4

3 回答 3

10

BEFOREMySQL 保留关键字。您需要用反引号将其引用以将其用作表或列标识符。

INSERT INTO images (image_name, orientation, restored, commercial, automotive, bespoke, `before`, after, date_added) 
VALUES ('image4-after.jpg', 'portrait', '1', '1', '1', '1', '24', '5', '2012-07-08')

AFTER但是,没有保留。

每当 1064 错误在其指示符中指向语法上不明显的内容时right syntax to use near...,请查看保留字列表。

于 2012-07-08T19:44:56.140 回答
3

BEFORE是一个关键字,根据MySQL 文档

尝试使用反引号 (`) 转义字段名称。

于 2012-07-08T19:45:16.437 回答
1

我猜这是因为 before 是 mysql 中的保留字(http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html)。

尝试用反向引号包围之前: before.

于 2012-07-08T19:46:25.687 回答