SQL Server Efficiently dropping a group of rows with millions and millions of rows

前端 未结 13 548
遇见更好的自我
遇见更好的自我 2021-02-04 12:26

I recently asked this question: MS SQL share identity seed amongst tables (Many people wondered why)

I have the following layout of a table:

Table: Star

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 13:31

    It sounds like the transaction log is struggling with the size of the delete. The transaction log grows in units, and this takes time whilst it allocates more disk space.

    It is not possible to delete rows from a table without enlisting a transaction, although it is possible to truncate a table using the TRUNCATE command. However this will remove all rows in the table without condition.

    I can offer the following suggestions:

    1. Switch to a non-transactional database or possibly flat files. It doesn't sound like you need atomicity of a transactional database.

    2. Attempt the following. After every x deletes (depending on size) issue the following statement

    BACKUP LOG WITH TRUNCATE_ONLY;

    This simply truncates the transaction log, the space remains for the log to refill. However Im not sure howmuch time this will add to the operation.

提交回复
热议问题