Solved

Oracle - Add partition (Alter table)

Posted on 2007-04-02
8
60,962 Views
Last Modified: 2014-03-16
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.
0
Comment
Question by:Mayank S
8 Comments
 
LVL 3

Expert Comment

by:kimarti3
ID: 18837822
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
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 50 total points
ID: 18838210
I believe your partition name must follow the add partition statement. Try this -
ALTER TABLE MY_TABLE ADD PARTITION DATA_98 BY RANGE (DATE_CREATED) VALUES LESS THAN (TO_DATE ('01/01/1999', 'DD/MM/YYYY'))
0
 
LVL 3

Expert Comment

by:kimarti3
ID: 18838245
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.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 30

Author Comment

by:Mayank S
ID: 18838268
>> 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"
0
 
LVL 3

Expert Comment

by:kimarti3
ID: 18838407
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.
0
 
LVL 30

Author Comment

by:Mayank S
ID: 18838413
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?
0
 
LVL 3

Accepted Solution

by:
kimarti3 earned 200 total points
ID: 18838447
Ohhh...if the table is not already partitioned, you need to recreate it as a partitioned table.
0
 
LVL 10

Expert Comment

by:dbmullen
ID: 39932586
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...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video shows how to recover a database from a user managed backup
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question