Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alantsai/16511d3c52da1056b88e6ad0e4cfa95d to your computer and use it in GitHub Desktop.
Save alantsai/16511d3c52da1056b88e6ad0e4cfa95d to your computer and use it in GitHub Desktop.
delete large data without transaction log full with no space

When delete large data showed

The transaction log for database '{db name}' is full due to 'ACTIVE_TRANSACTION'.

which means there is no more space for log

if you don't have that much space for large delete, do it in chunks

more info checkout

https://stackoverflow.com/questions/1448857/there-must-be-a-way-to-delete-data-in-sql-server-w-o-overloading-the-log

DECLARE @Done BIT
SET @Done = 0
WHILE @Done = 0
  BEGIN
    DELETE TOP (20000) -- reduce if log still growing
      FROM SomeTable WHERE SomeColumn = SomeValue 
    IF @@ROWCOUNT = 0 
      SET @Done = 1
    CHECKPOINT -- marks log space reusable in simple recovery
  END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment