Search

Thursday, July 28, 2011

To delete huge amount of data without filling the log file

If you put the database in Simple Mode and run the following code;

SET ROWCOUNT 10000
WHILE 1=1
BEGIN
DELETE from sys.syslogdata
where msghostname = 'SERVER.it.Dev.com'
IF @@ROWCOUNT = 0 BREAK
END

you won´t get a logfile that grows to much. It will delete 10.000 rows (or as much as you descibes in 'rowcount').

After each time you do this it will put a checkpoint and can reuse the log again. If you change the delete part it can be used in many situations

If you want all data in a table to be deleted 'truncate table' is much faster!

!! At delete you won´t reset a counter, this will be done with a truncate. If you want to reset a counter you may want to look into 'CHECKIDENT'.

No comments:

Post a Comment