Solved

Oracle - Add partition (Alter table)

Posted on 2007-04-02
8
60,620 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
migration MS SQL database to Oracle 30 62
Mongo DB 18 46
Oracle Query - Convert letters to numbers and display the difference 3 27
SQL Query assistance 16 27
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

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