MySQL is not on Insert, there will Update. INSERT ... ON DUPLICATE KEY UPDATE Syntax

Summary: MySQL is not on Insert, there will Update. INSERT ... ON DUPLICATE KEY UPDATE Syntax


http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

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

If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUEindex or PRIMARY KEY, an UPDATE of the old row is performed. For example, if column a is declared as UNIQUEand contains the value 1, the following two statements have identical effect:

Only be used in Privary key or UNIQUE

Original: Big Box  MySQL not to Insert, there will Update. INSERT ... ON DUPLICATE KEY UPDATE Syntax


Guess you like

Origin www.cnblogs.com/petewell/p/11495645.html