Created
June 7, 2025 07:49
-
-
Save OOOlledj/20debc1a61fb8d21becfb7ea1e284c92 to your computer and use it in GitHub Desktop.
MS SQL SERVER - delete rows in loop with transaction
This file contains hidden or 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
| --delete from dbo._InfoRg43805X1; | |
| DECLARE @counter INT = 1; | |
| WHILE @counter <= 1000 | |
| BEGIN | |
| --PRINT 'Waitting 5 seconds delay...'; RAISERROR(N'',0,1) WITH NOWAIT; | |
| WAITFOR DELAY '00:00:10' | |
| BEGIN TRANSACTION; | |
| PRINT 'Transaction : ' + CAST(@counter AS VARCHAR(4)); RAISERROR(N'',0,1) WITH NOWAIT; | |
| --PRINT 'Transaction N started!: ' + CAST(@counter AS VARCHAR(4)); RAISERROR(N'',0,1) WITH NOWAIT; | |
| DELETE TOP(11000) FROM dbo._InfoRg43805X1; | |
| --PRINT 'Transaction N is going to be commited: ' + CAST(@counter AS VARCHAR(3)); RAISERROR(N'',0,1) WITH NOWAIT; | |
| COMMIT; | |
| --PRINT 'Transaction N Commited!: ' + CAST(@counter AS VARCHAR(4)); RAISERROR(N'',0,1) WITH NOWAIT; | |
| SET @counter = @counter + 1; | |
| END; | |
| --select count(*) from dbo._InfoRg43805X1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment