Purge by deleting all records older than 180 days from the current date in SQL Server -
in sql server 2008 r2 have table (database size 450 gb) on billion rows, i'd purge deleting records older 180 days counting current date. here appreciated!
i'm using following query :
delete table name column name < '2015-01-01'
but taking time. there maintenance plan or query can delete data fast?
one approach might save time:
- start off taking backup (you never know)
- insert rows want keep temporary table (make sure have enough room on disk
tempdb
) truncate
table remove rows (this statement execute instantly)- insert rows temporary table source table
insert #keep select * table_name column_name>='2015-01-01'; truncate table table_name; insert table_name select * #keep; drop table #keep;
Comments
Post a Comment