• The explicit BEGIN TRAN, COMMIT TRAN in the batch delete is unnecessary, SQL will by default commit each individual statement, unless you put a transaction around the entire process. Totally agree about using a clustered key for batching (or a non-clustered index on a heap).

    Here's my simpler version of the batch delete (for both SQL 2005 and 2000):

    --SQL 2005+

    DECLARE @i INT

    SET @i = 1

    WHILE @i > 0

    BEGIN

    DELETE TOP (10000) FROM dbo.SuperBigTable

    WHERE RecordID < 12345

    SELECT @i = @@ROWCOUNT

    END

    --SQL 2000

    DECLARE @i INT

    SET @i = 1

    SET ROWCOUNT 10000

    WHILE @i > 0

    BEGIN

    DELETE * FROM dbo.SuperBigTable

    WHERE RecordID < 12345

    SELECT @i = @@ROWCOUNT

    END

    SET ROWCOUNT 0

    Had to use this again this morning, a user tried to delete 88m rows out of a 90m row table, all in one statement. I told him not to do that 🙂