Deleting in a loop in SQL Server

While discussing a way to delete many rows, but without deleting all of them at the same time (too much transaction logging), we came up with the following…

This works pretty well. It’s faster to do it all at once, but if that isn’t doable, and you can’t do the normal create a table copy with only what you want to keep, or use partitioning, etc., you can use this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.