SQL-重复键更新 [英] Sql - ON DUPLICATE KEY UPDATE
本文介绍了SQL-重复键更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用此语句更新整行
How do I update the entire row with this statement
INSERT INTO table (a,b,c) VALUES (1,2,3)
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.
这篇关于SQL-重复键更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文