How to efficiently delete rows while NOT using Truncate Table in a 500,000+ rows table

后端 未结 8 1420
死守一世寂寞
死守一世寂寞 2020-11-30 01:30

Let\'s say we have table Sales with 30 columns and 500,000 rows. I would like to delete 400,000 in the table (those where \"toDelete=\'1\'\").

8条回答
  •  [愿得一人]
    2020-11-30 01:41

    Calling DELETE FROM TableName will do the entire delete in one large transaction. This is expensive.

    Here is another option which will delete rows in batches :

    deleteMore:
    DELETE TOP(10000) Sales WHERE toDelete='1'
    IF @@ROWCOUNT != 0
        goto deleteMore
    

提交回复
热议问题