I have a DB that is about 3.5GB. 2 tables use most spaces. each table has about 2.8M rows. now I need to delete about 1.9M rows from each table. using the batch delete
- DELETE TOP (n) syntax, then loop until now more needs to be deleted
it seems we controlled the log size problem. however, the performance downgraded a lot. for example, if I delete the data from the first table A in one batch (delete from ...), it takes about 9 minutes. Now, if I delete in a batch of 2000, after the whole night, it does not finish yet. If I get the # of rows that will be deleted, then batch delete 10% of it in each loop (so, about 200,000 for each batch), it takes about 40 minutes.
Is this normal? one thing I want to point out is: there is no primary key in these 2 tables, although they have non-cluster index. it was designed by previous developer who never thought we would have so much data to process. Now, we have to live with this, change database structure is not an option. Could it because of this that makes the delete slow?
Any suggest of what can cause the slow?
DELETE
look like, how you defineTOP
(e.g. is there anORDER BY
or do you like random), why is there no primary key or clustered index, what recovery model, what else are you doing in the loop (e.g. backing up the log, checkpoint), ...?