Best way to update 40 million rows in batch

后端 未结 4 1082
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 07:56

Basically I need to run this on a table with 40 million rows, updating every row at once will crash, so I want to batch the query so that if it crash, it can re-run the quer

4条回答
  •  梦谈多话
    2021-01-05 08:42

    Fastest way is to :

    1) Create a temp table and insert all the values from old to temp table using the create(select having condition) statement.

    2) Copy the constraints and refresh the indexes.

    3) Drop the old table.

    4) Rename temp table to original name.

    Complete discussion is available on this link

提交回复
热议问题