When you performing a huge DELETE operation with or without where clauses, transaction log might take over SQL server hard disk and it might takes long time to complete. But delete in chunks: 50,000 or 100,000 rows at a time might solve this issue.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
SET NOCOUNT ON; DECLARE @rows INT; DECLARE @chunksize INT; SET @rows = 1; SET @chunksize =100000; WHILE @rows > 0 BEGIN BEGIN TRANSACTION DELETE TOP (@chunksize) FROM [databasename] SET @rows = @@ROWCOUNT; COMMIT TRANSACTION END |
Leave a Comment