MYSQL ONDUPLICATE KEY UPDATE ISSUE

时间:2016-06-15 07:56:23

标签: mysql

我正在尝试使用' ON DUPLICATE KEY UPDATE'当重复的主键已经在表中时更新列的语句。 但即使表有重复的主键,它也不会更新列。

以下是“重复主题更新”'声明。 有什么不对吗?

 ON DUPLICATE KEY UPDATE authenticated = authenticated
                  and notAuthenticated = notAuthenticated
                  and stoped = stoped
                  and deleted = deleted
                  and updatedDate = now()

2 个答案:

答案 0 :(得分:4)

使用VALUES(Column)并用逗号AND替换所有,

 ON DUPLICATE KEY UPDATE authenticated = VALUES(authenticated),
                  notAuthenticated = VALUES(notAuthenticated),
                  stoped = VALUES(stoped),
                  deleted = VALUES(deleted),
                  updatedDate = now() 

答案 1 :(得分:1)

不要使用AND,但请使用逗号:

 ON DUPLICATE KEY UPDATE
              authenticated = VALUES(authenticated),
              notAuthenticated = VALUES(notAuthenticated),
              stoped = VALUES(stoped),
              deleted = VALUES(deleted),
              updatedDate = now()