MySql INSERT失败

时间:2011-04-22 13:16:55

标签: mysql syntax

为什么以下查询在MySql上失败?

NHibernate: INSERT INTO UserSetting (userId, key, value) VALUES (?p0, ?p1, ?p2); ?p0 = ccda78da-689d-4d86-ba72-d65eaf281edf [Type: Guid (0)], ?p1 = 'Hello' [Type: String (5)], ?p2 = 'World' [Type: String (5)]

出现此错误:

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 'key, value) VALUES ('ccda78da-689d-4d86-ba72-d65eaf281edf', 'Hello', 'World')' at line 1"}

2 个答案:

答案 0 :(得分:4)

key是保留字。

试试这个:

INSERT INTO UserSetting (userId, `key`, value) VALUES (?p0, ?p1, ?p2)

答案 1 :(得分:2)

Key是保留字,使用ticks,链接中的示例

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html