Link to home
Start Free TrialLog in
Avatar of Mayank S
Mayank SFlag for India

asked on

Oracle - Add partition (Alter table)

Hi folks,

I have a table already created on which I want to add a partition by range on a date column. I checked for for the syntax on the Net and most of them:

1. Either explain the syntax for partitions specified while creating the table: (e.g., http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10739/partiti.htm)

2. Or specify it without the column-name while partitioning (e.g., http://www.databasedesign-resource.com/oracle-partitions.html) - does that assume by default that partitioning will be done on the primary key?

I know I might not have looked enough but am just looking for a sample Alter table command which adds a partition by range on a column which is not the primary key. Maybe something like the correct syntax for:

ALTER TABLE MY_TABLE ADD PARTITION BY RANGE (DATE_CREATED) DATA_98 VALUES LESS THAN (TO_DATE ('01/01/1999', 'DD/MM/YYYY'))

Thanks,
Mayank.
Avatar of kimarti3
kimarti3

Here is a good article that explains partitions and how to add them.  http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96521/partiti.htm#6536
SOLUTION
Avatar of awking00
awking00
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As another note, it depends on if the column in question is indexed.  If its indexed, you have to use different syntax, which is explained in the link I added before.
Avatar of Mayank S

ASKER

>> http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96521/partiti.htm#6536

That link is almost the same as the 1st one which I posted (they look like 2 different versions of the same tutorial) - doesn't explain how to add a partition on a specific column by altering the table. Though it explains how to create and alter (without specifying a column).

>> ALTER TABLE MY_TABLE ADD PARTITION DATA_98 BY RANGE (DATE_CREATED)
>> VALUES LESS THAN (TO_DATE ('01/01/1999', 'DD/MM/YYYY'))

I'd hope that will work :( but it gave an error "ORA-14020: this physical attribute may not be specified for a table partition"
Are you inserting a partition between partitions?  or are you adding a partition after the last partition?  If you are adding a partition between existing partitions, you have to use the SPLIT PARTITION clause.

I know we have partitions on our database...but when we wanted to add more partitions to the table...we found out the best and easiest way to do this is to export the data, recreate the table with more partitions and then import the data.
Let me clarify - the table is not partitioned. Can I partition it and add partitions to it? Or do I need to recreate the table?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the "GOAL" is to get the "going" forward dates into daily partitions, I have used the EXCHANGE method.  what that does is puts EVERYTHING into one BIG old partition and going forward will follow your partition strategy.


http://www.oracle-base.com/articles/misc/partitioning-an-existing-table-using-exchange-partition.php

if the GOAL is to get existing data into the correct partitions, create new and insert as select.
or create table as select...

sorry...