Solved

Oracle - Add partition (Alter table)

Posted on 2007-04-02
8
59,802 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:mayankeagle
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 31

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
 
LVL 30

Author Comment

by:mayankeagle
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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:mayankeagle
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now