Sql-server – MSSQL Large Delete

sql serversql-server-2005

I have a table within a MSSQL database that contains more than 100 Million records spread over about 100 days worth of data. I need to purge some of this data based on its date which is an indexed field in the table. I've tried doing a DELETE FROM against an individual date but it was taking a long long time to execute and was causing a drop in server performance. Is there a better way of deleting such a large number of records? Some of this data is still required so unfortunately I can't use truncate.

Many Thanks
Nick

Best Answer

I have had the best success when doing similar tasks with the following flow:

  1. Copy the data to keep into a temporary table
  2. Truncate the original table to purge all data
  3. Move everything from the temporary table back into the original table

One major benefit of this is that your indexes will be rebuilt as you put the data back into the original table.