Assuming a brief period with the table unavailable, you may consider this. It's a variation of the usual way of bcp'ing out the data to be saved, truncate the table, drop indexes, bcp in only the good data and recreate the indexes.
- Build a similar table, loaded with the data you wish to keep
- Ban access to the table
- Use sp_rename to swap table names. Now, the good table is the one you built with fewer data
- Copy the latest inserts, those arrived after you built the table
- Grant access again
A warning about sp_rename: views, stored procedures and triggers will still refer to the old table, so they need to be droped and created if contain references to the table.
Regards,
Mariano Corral
Quote:
|
Originally Posted by anitaarbabi
Hi,
I'm trying to trim down a huge table in sybase database. We have around 25 million rows in the table from 1997. We want to keep the most recent three years and delete the rest. The thing is we cannot shut down the database and it should remain functional during the process.
|