views:

46

answers:

1

I would like to know if the following steps are possible and how fast this is:

  1. Create a partition named part1 in Table A
  2. Drop partition part1 in Table B
  3. Import the Table A partition part1 into Table B

Can you provide me with an example if it is possible indeed? Or any resources I can look at?

Note that the tables would have the exact same structure.

+1  A: 

You can do something similar with the ALTER TABLE ... EXCHANGE PARTITION command. This would exchange a single partition with a table that has the same structure.

A little example:

/* Partitionned Table Creation */
SQL> CREATE TABLE table_a (
  2     ID NUMBER PRIMARY KEY,
  3     DATA VARCHAR2(200)
  4  )
  5  PARTITION BY RANGE (ID) (
  6     PARTITION part100 VALUES LESS THAN (100),
  7     PARTITION part200 VALUES LESS THAN (200)
  8  );

Table created

/* Swap table creation */
SQL> CREATE TABLE swap_table (
  2     ID NUMBER PRIMARY KEY,
  3     DATA VARCHAR2(200)
  4  );

Table created

SQL> INSERT INTO swap_table SELECT ROWNUM, 'a' FROM dual CONNECT BY LEVEL <= 99;

99 rows inserted

SQL> select count(*) from table_a partition (part100);

  COUNT(*)
----------
         0

This will exchange the partition part100 with the transition table swap_table:

SQL> ALTER TABLE table_a EXCHANGE PARTITION part100 WITH TABLE swap_table;

Table altered

SQL> select count(*) from table_a partition (part100);

  COUNT(*)
----------
        99
Vincent Malgrat