ON DUPLICATE KEY UPDATE

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ON DUPLICATE KEY UPDATE相关的知识,希望对你有一定的参考价值。

 

 

14.2.5.3 INSERT ... ON DUPLICATE KEY UPDATE Syntax

If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, mysql performs an UPDATE of the old row. For example, if column a is declared as UNIQUE and contains the value1, the following two statements have similar effect:

INSERT INTO table (a,b,c) VALUES (1,2,3)
  ON DUPLICATE KEY UPDATE c=c+1;

UPDATE table SET c=c+1 WHERE a=1;

(The effects are not identical for an InnoDB table where a is an auto-increment column. With an auto-increment column, an INSERT statement increases the auto-increment value but UPDATE does not.)

The ON DUPLICATE KEY UPDATE clause can contain multiple column assignments, separated by commas.

以上是关于ON DUPLICATE KEY UPDATE的主要内容,如果未能解决你的问题,请参考以下文章

为什么不建议使用ON DUPLICATE KEY UPDATE

为什么不建议使用ON DUPLICATE KEY UPDATE

讲讲insert on duplicate key update 的死锁坑

MySQL INSERT ON DUPLICATE KEY UPDATE

MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)

INSERT ... ON DUPLICATE KEY UPDATE Syntax