2012-07-08 34 views
2

所以我一直卡在这个sql错误一段时间。不寻常的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服务器版本的手册,以便在'before,after,date_added'附近使用 )正确的语法VALUES('image4-after.jpg', 'portrait','1','1','1在1号线

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

感谢“”

+0

请张贴架构。 – djdy 2012-07-08 19:44:25

+0

所有的文章都是文字吗? – Raekye 2012-07-08 19:44:59

+1

^这些东西都没有与语法错误有关 – Esailija 2012-07-08 19:54:46

回答

10

BEFOREMySQL reserved keyword。你需要用反引号引用它来使用它作为一个表或列标识符。

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...指示符中语法上指向非明显的语句时,请查看保留字列表。

+0

这很好解释了很多!感谢那疯狂的回应时间:) – alsweet 2012-07-08 19:48:33

1

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

尝试使用向后的引号前进:before