BNFD - Your DBA NoteBook On The Net!!!

Monday, February 11, 2008

How to partition a non-partitioned table

You can partition a non-partitioned table three different ways:

A. Export/Import method
B. Partition exchange method
C. Insert with a sub-query method

Any of these 3 methods will create a partitioned table from

an existing non-partitioned table. Here we are considering that EMP is a non-partitioned table.

A. Export/import method

1) Export non-partitioned EMP table:
exp username/password tables=emp file=emp_exp.dmp log=emp_exp.log

2) Drop the table:
drop table emp;

3) Recreate EMP table with partitions:
create table EMP (empo number(3), name varchar2(15)) partition by range (qty) (partition p1 values less than (501), partition p2 values less than (maxvalue));

4) Import the table with ignore=y:
imp usr/pswd file=exp.dmp ignore=y The ignore=y causes the import to skip the table creation and continues to load all rows.

B. Insert with a subquery method

1) Create a partitioned table:
create table EMP_PART (empo number(3), name varchar2(15)) partition by range (qty) (partition p1 values less than (501), partition p2 values less than (maxvalue));

2) Insert into the partitioned table with a subquery from the non-partitioned table:
insert into EMP_PRAT (qty, name) select * from EMP Note: EMP is a non-partition table.

3) If you want the partitioned table to have the same name as the original table, then drop the original table and rename the new table:
drop table EMP; alter table EMP_PART rename to EMP;

C. Partition Exchange method
ALTER TABLE EXCHANGE PARTITION can be used to convert a partition (or subpartition) into a non-partitioned table and a non-partitioned table into a partition (or subpartition) of a partitioned table by exchanging their data and index segments.

1) Create table dummy_t as select with the required partitions
2) Alter table EXCHANGE partition with ;

Example
-------
SQL> CREATE TABLE p_emp 2 (sal NUMBER(7,2)) 3 PARTITION BY RANGE(sal) 4 (partition emp_p1 VALUES LESS THAN (2000), 5 partition emp_p2 VALUES LESS THAN (4000));
Table created.

SQL> SELECT * FROM emp;
EMPNO ENAME JOB MGR HIREDATE SAL --------- ---------- --------- --------- --------- --------- 7369 SMITH CLERK 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250 7566 JONES MANAGER 7839 02-APR-81 2975 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 7698 BLAKE MANAGER 7839 01-MAY-81 2850 7782 CLARK MANAGER 7839 09-JUN-81 2450 7788 SCOTT ANALYST 7566 19-APR-87 3000 7839 KING PRESIDENT 17-NOV-81 5000 7844 TURNER SALESMAN 7698 08-SEP-81 1500 7876 ADAMS CLERK 7788 23-MAY-87 1100 7900 JAMES CLERK 7698 03-DEC-81 950 7902 FORD ANALYST 7566 03-DEC-81 3000 7934 MILLER CLERK 7782 23-JAN-82 1300
14 rows selected.

SQL> CREATE TABLE dummy_y as SELECT sal FROM emp WHERE sal<2000;> CREATE TABLE dummy_z as SELECT sal FROM emp WHERE sal BETWEEN 2000 AND 3999;
Table created.

SQL> alter table p_emp exchange partition emp_p1 with table dummy_y;
Table altered.

SQL> alter table p_emp exchange partition emp_p2 with table dummy_z;
Table altered

9 comments:

Anonymous said...

Very shortly this website will be famous among all blogging and
site-building people, due to it's pleasant posts
Feel free to surf my page - free usa online casinos

Anonymous said...

I know this site provides quality depending posts and
additional information, is there any other web site which provides these kinds
of data in quality?
Also see my site - the best affiliate programs

Anonymous said...

Wonderful post but I was wondering if you could write a litte more
on this topic? I'd be very grateful if you could elaborate a little bit more. Many thanks!
Feel free to visit my blog post ; real money slots online

Anonymous said...

I do accept as true with all of the ideas you've presented on your post. They are really convincing and will definitely work. Nonetheless, the posts are too brief for novices. May just you please lengthen them a little from next time? Thanks for the post.
My web site ... play slots For real money

Anonymous said...

Undeniably consider that which you stated. Your favourite reason appeared to be at the
web the easiest factor to take into accout of. I say to you, I definitely
get irked even as other folks consider concerns that they plainly do not know about.
You managed to hit the nail upon the top as smartly as outlined out the entire thing with no need side-effects , other folks can take
a signal. Will probably be back to get more. Thank you
Here is my page :: slot machines online real money

Anonymous said...

I am extremely inspired along with your writing abilities as neatly as with the layout on your weblog.
Is this a paid topic or did you modify it yourself?
Anyway stay up the excellent high quality writing, it is uncommon to see a nice blog like
this one these days..
Also visit my blog ... random number generator online

Anonymous said...

I am extremely inspired along with your writing abilities as neatly as with the layout on your weblog.
Is this a paid topic or did you modify it yourself? Anyway stay up the excellent high quality writing, it is
uncommon to see a nice blog like this one these days.
.
Also see my web site - random number generator online

Anonymous said...

This post will help the internet users for setting up new webpage or even a blog from start to
end.
My homepage ; play online slots for real money

sheyne said...

why not look here replica bags buy online official website luxury replica bags Recommended Site YSL Dolabuy