If I have a table with huge amount of data…and If I do incremental delete instead “one time delete”..what’s the benefit ?
Onetime delete
DELETE table_1
WHERE BID = @BID
AND CN = @CN
AND PD = @PD;
Incremental Delete
While (1=1)
Begin
DELETE TOP (100000) FROM table_1
WHERE BID = @BID
AND CN = @CN
AND PD = @PD;
If @@rowcount = 0 -- No row affected.
BREAK
ELSE
Continue
End
I got help from
Deleting data in a sql server table takes much time
Depends on the configuration, I have seen large deletes blow up the transaction log and cause a failure in not enough disk space.
You could also avoid locking escalation by using a smaller batch.