开发者

Sql - ON DUPLICATE KEY UPDATE

开发者 https://www.devze.com 2023-03-25 09:16 出处:网络
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;

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

精彩评论

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