Skip to content


使用INSERT INTO … ON DUPLICATE KEY… 批量插入或更新

update和replace没有同时操作多条记录的语句,
可以用insert … on durlicate key…代替,可以同时插入或更新多条记录

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

如果键a有重复则更新b和c字段,没有则插入

Posted in Mysql, 技术.

Tagged with .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.