Using Sybase ASE 15 for this - I have about a large amount of rows (up to 10 mil) to delete from a table on a regular basis, but I want to keep a selection of the latest added data to the table, so that rules out using truncate directly on the table.
delete from master_table where...
Using the above delete is very slow, so my strategy is to move the data I want to keep into a temp table, truncate the master table and move the data back in again from the temp table i.e.
1) select * into #temp_table from master_table where date_updated > dateadd(mi, -15, getdate()) and node_type != 'X'
2) truncate table master_table
3) insert into master_table select * from #temp_table
This is almost good enough - 1 & 2 have great performance, but the insert back into the master is too slow.
So my question really boils down to whether there a quick way of doing either of:
delete from master_table where...
insert into xyz select * from...
Or I'm open to alternative approaches!