Q

UNIQUE index vs. PRIMARY KEY constraint to rebuild Oracle indexes and constraints

An Oracle user asks whether it's redundant to use both a UNIQUE index and a PRIMARY KEY constraint to rebuild Oracle indexes and constraints on a very large table.

I am rebuilding indexes and constraints on a very large table and need to accomplish this as fast as possible.

If I create a UNIQUE index on this table (4 concatenated not null columns) AND use the alter table command to enforce...

the primary key, is this totally redundant?

Here are the statements I'm using and the elapsed time it is taking.

1) Create unique index X on X nologging (53 minutes).

2) Alter table X add constraint X primary key (col1, col2, col3) using index (one hour 50 minutes).

Technically, a UNIQUE index and a PRIMARY KEY constraint are a little different. Both enforce uniqueness, but the PK constraint also ensures that all values in the columns cannot be NULL. But to cut down on the time, I would just perform one statement, the ALTER TABLE ADD CONSTRAINT command. This will build the index and enable the constraint in one operation.
This was last published in December 2008

Dig Deeper on Oracle database administration

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close