码迷,mamicode.com
首页 > 其他好文 > 详细

ON DUPLICATE KEY UPDATE

时间:2016-11-11 17:28:15      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:sim   table   nts   sig   increase   tab   title   val   5.7   

 

 

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

标签:sim   table   nts   sig   increase   tab   title   val   5.7   

原文地址:http://www.cnblogs.com/studyNT/p/6054947.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!