Solved

Oracle - Add partition (Alter table)

Posted on 2007-04-02
8
61,678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.

689 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