So I now have the need to delete a few million records from a few tables. Ive been burned before, so I know this much be done in stages or else it will fill up the transaction log and grind your database to a halt. I was reading a few other threads on this, such as this one. So why is it that deleting records in batches of say 10,000 at a time, willnot grow the transaction log, whereas trying to delete all 1 million at once will?
So, something like this, would delete in batches of 10,000.
But wouldnt the same number of records get written to the transaction log either way?
As far as the tlog is concerned, what is the difference between this as say, just deleting everything in one large batch?
DECLARE @continue INT DECLARE @rowcount INT SET @continue = 1 WHILE @continue = 1 BEGIN PRINT GETDATE() SET ROWCOUNT 10000 BEGIN TRANSACTION DELETE FROM some_big_table WHERE ... SET @rowcount = @@rowcount COMMIT PRINT GETDATE() IF @rowcount = 0 BEGIN SET @continue = 0 END END