Search code examples
oracleoracle11gpartitioning

How to detach a partition from a table and attach it to another in oracle?


I have a table with huge data( say millions of records, its just a case study though!) of 5 years, with a partition for each year. Now i would want to retain the last 2 years data, and transfer the rest of the 3 year data to a new table called archive?

What would be the Ideal method, with minimal down time and high performance?


Solution

  • alter table exchange partition 
    

    is the answer. This command exange the segment of a partition with the segment of a table. It is at light speed because it does only some reference interchages. So, you need some temp tables, because AFAIK you can't exchange them directly.

    Something like:

    create table tmp_table(same columns);
    Add partition p_2011 in table ARCH_TABLE;
    
    ALTER TABLE CURR_TABLE EXCHANGE PARTITION P_2011 WITH TABLE tmp_table;
    ALTER TABLE ARCH_TABLE EXCHANGE PARTITION P_2011 WITH TABLE tmp_table;
    

    Please test test your code before run.