我看不懂这条sql语句有什么问题
INSERT INTO tbl_car_model_year_rate
SET car_model_id =4,
FROM =2008,
TO =2011,
with_driver =1,
per_day =1000,
ten_days =10000,
twenty_days =20000,
thirty_days =30000,
image = '1303166512test.jpg',
created_at = NOW( ) ,
created_by =1
数据类型
car_model_id int(11)
image text
from year(4)
to year(4)
with_driver tinyint(1)
per_day int(11)
ten_days int(11)
twenty_days int(11)
thirty_days int(11)
created_at datetime
created_by int(11)
错误信息
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 'from =2008, to =2011, with_driver =1, per_day =1000, ten_days =10000, twenty' at line 1
最佳答案
如果您将代码更改为:
INSERT INTO tbl_car_model_year_rate SET car_model_id =4,
`FROM` =2008,
`TO` =2011,
with_driver =1,
per_day =1000,
ten_days =10000,
twenty_days =20000,
thirty_days =30000,
image = '1303166512test.jpg',
created_at = NOW( ) ,
created_by =1
它会起作用的。 如果您在反引号“`”中添加字段和/或表名称,那么您几乎可以为它们使用任何名称。
失败原因
FROM
是保留字(如 select *
FROM
tablename
)
您通过使用 FROM
作为列名来混淆 MySQL (select * FROM FROM WHERE FROM = AND
)
我的推荐
不要对字段名使用保留字。
将列名称从 FROM
更改为 YearFrom
或 StartYear
从 TO
到 YearTo
或 EndYear
。
使用保留字作为列名只会让人感到困惑,在所有内容周围添加反引号只会让内容难以阅读和丑陋,同时仍然令人困惑。
关于php - 如何在 MySQL 中设置年份数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5709812/