Multiple Updates in MySQL

前端 未结 17 1022
南方客
南方客 2020-11-22 01:31

I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL?

Edit: For example I have the followi

17条回答
  •  忘了有多久
    2020-11-22 01:44

    use

    REPLACE INTO`table` VALUES (`id`,`col1`,`col2`) VALUES
    (1,6,1),(2,2,3),(3,9,5),(4,16,8);
    

    Please note:

    • id has to be a primary unique key
    • if you use foreign keys to reference the table, REPLACE deletes then inserts, so this might cause an error

提交回复
热议问题