开发者

Sql - ON DUPLICATE KEY UPDATE

How do I update the entire row with this statement

INSERT INTO table (a,b,c) VALUES (1,2,3)
开发者_JAVA百科  ON DUPLICATE KEY UPDATE c=c+1;

But I want to update all fields besides the primary key which auto-increments. How?


Just add them to the second row like this:

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

On multiple inserts at once, you can refer to the values like this:

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

Have look at the Docs for more info on syntax.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜