摘要:MySQL 沒有就Insert,有就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 UNIQUE
index or PRIMARY KEY
, an UPDATE
of the old row is performed. For example, if column a
is declared as UNIQUE
and contains the value 1
, the following two statements have identical effect:
只能用在Privary key 或UNIQUE