Question : How to do a bulk delete without growing transaction log?

We are trying to delete the contents of a large table quickly and without growing the transaction log (substantially).

DELETE FROM TableName -- Issues one delete per row, huge transaction log, really slow.
TRUNCATE TableName -- You can only do this if the table is not referenced by other tables.

Any other ideas?  

I'd like to see a simple query that deletes in batches of one million and gets all the records.  Any idas?

We have both SQL 2000 and SQL 2008.

Answer : How to do a bulk delete without growing transaction log?

disable the indexes on the table first

ALTER INDEX IndexName ON tableName DISABLE
GO

while 1 = 1
begin

delete top ( 10000 )
from tablename
where Someconition
 
if @@rowcount = 0 BREAK

end

ALTER INDEX IndexName ON tableName enable
GO

ALTER INDEX IndexName ON tbMessages REBUILD
GO
Random Solutions  
 
programming4us programming4us