Slow bulk insert for table with many indexes

前端 未结 4 2159
野的像风
野的像风 2020-12-02 15:52

I try to insert millions of records into a table that has more than 20 indexes.

In the last run it took more than 4 hours per 100.000 rows, and the query was cancell

4条回答
  •  渐次进展
    2020-12-02 16:27

    You can disable and enable the indexes. Note that disabling them can have unwanted side-effects (such as having duplicate primary keys or unique indices etc.) which will only be found when re-enabling the indexes.

    --Disable Index
    ALTER INDEX [IXYourIndex] ON YourTable DISABLE
    GO
    
    --Enable Index
    ALTER INDEX [IXYourIndex] ON YourTable REBUILD
    GO
    

提交回复
热议问题