A common technique to age out old data is to swap an empty partition (table) for the data you want to delete. The SWITCH only changes meta data so the billion rows are not moved on the media. After they are switched you can backup and drop the table. There is some overhead dropping and recreating the clustered index but there are no deletes or inserting/moving of data.
CREATE TABLE [dbo].[LargeTable]( [RecordDate] [datetime] NOT NULL, [intCol] [int] NULL, [charCol] [char](10) NULL ) ON [PRIMARY] INSERT LargeTable(RecordDate,intCol,charCol) VALUES('4/30/2009',1,'historical') ,('5/31/2010 23:59:59.997',2,'historical') ,('6/1/2010',3,'keep data') ,('10/28/2010',4,'keep data') -- drop your existing CLUSTERED index here. --DROP INDEX blah blah -- create table identical to your original large table, same columns, -- same column order, same column nullability, collation etc -- it must contain the same primary key contstraint,foreign key constraints,check constraints, -- non-clustered indexes, clustered index(we dropped ours above, however), -- computed columns etc as the original -- the original table cannot be referenced by a foreign key in another table. drop these then after -- the switch recreate them -- the date column used for partitioning should be NOT NULL in both tables -- the new historical table must be empty and must be on the same filegroup -- as the original table CREATE TABLE [dbo].[LargeTableHistory]( [RecordDate] [datetime] NOT NULL, [intCol] [int] NULL, [charCol] [char](10) NULL ) ON [PRIMARY] -- same filegroup -- cluster our partition column CREATE CLUSTERED INDEX cidx ON [LargeTableHistory] (RecordDate) CREATE PARTITION FUNCTION [RecordDateRangePF] (datetime) AS RANGE RIGHT FOR VALUES ('20100601') -- save everything from 6/1/2010 and later CREATE PARTITION SCHEME [RecordDateRangePS] AS PARTITION [RecordDateRangePF] ALL TO ([PRIMARY]) -- create interim clustered index to align table with partition scheme CREATE CLUSTERED INDEX cidx ON [LargeTable] (RecordDate) ON [RecordDateRangePS]([RecordDate]) -- do magick -- ALTER TABLE [LargeTable] SWITCH PARTITION 1 TO [LargeTableHistory] SELECT * FROM [LargeTable] SELECT * FROM [LargeTableHistory] -- drop the interim clustered indexes DROP INDEX [LargeTable].cidx DROP INDEX [LargeTableHistory].cidx -- recreate the real clustered index on original table CREATE CLUSTERED INDEX cidx ON [LargeTable] (intCol) ON [PRIMARY] -- backup first, then drop the historical data DROP TABLE [LargeTableHistory]
-- clean up DROP PARTITION SCHEME [RecordDateRangePS] DROP PARTITION FUNCTION [RecordDateRangePF] -- obviously you wont do this :) DROP TABLE [LargeTable]
No one has followed this question yet.