MySQL ON DUPLICATE KEY UPDATE 解析

Update repeated insertion MySQL ON DUPLICATE KEY UPDATE.

ON DUPLICATE KEY UPDATE used in the insert statement will result in a duplicate value UNIQUE index or PRIMARY KEY, the old data at this time (OK) an UPDATE operation. The following two statements have the same effect in which the primary key id.

mysql>INSERT INTO test1 (id,name,age) VALUES (100,'test1',3) ON DUPLICATE KEY UPDATE age = age + 1;
mysql>UPDATE test1 SET age = age + 1 WHERE id = 100;

 

Guess you like

Origin blog.csdn.net/uvyoaa/article/details/85234088