Last active
August 29, 2015 14:18
-
-
Save syron/ec39e575496e30d2c185 to your computer and use it in GitHub Desktop.
SQL loop to delete x rows at a time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @rowCount INT | |
, @rowsToDelete INT = 5000 | |
, @highestDate DATETIME2(7) = '2015-03-01' | |
WHILE 1 = 1 | |
BEGIN | |
DELETE TOP (@rowsToDelete) T FROM Table T | |
WHERE T.DateTimeColumn < @highestDate | |
SET @rowCount = @@ROWCOUNT | |
IF @rowCount <> @rowsToDelete | |
BREAK | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment