INSERT与重复键更新

时间:2013-08-14 01:39:04

标签: mysql

我很难理解带有重复密钥更新检查的插入的正确语法。

我目前收到查询错误:

INSERT INTO users_items (q,id,uid)
ON DUPLICATE KEY UPDATE
q = q + ?, id = ?, uid = ?  

唯一键是uid + id

我的错误是:

 Syntax error or access violation: 1064 You have an error in your SQL syntax;

1 个答案:

答案 0 :(得分:1)

VALUES是必填部分(或SETSELECT

INSERT INTO users_items (q,id,uid)
VALUES (v1, v2, v3) -- <<< this is what you missed
ON DUPLICATE KEY UPDATE
q = q + ?, id = ?, uid = ?

Referene: