Q
Problem solve Get help with specific problems with your technologies, process and projects.

Why do primary keys need unique indexes?

Why do primary key constraints require that a unique index be created to support the key? I can understand this for foreign key constraints but not primary ones. Since the primary key requires storage parameters, doesn't that imply that there is an associated structure that would serve as the index? Doesn't this dual structure add overhead? Also, if the unique index were needed for a primary key constraint, why wouldn't you just use a unique index? Thanks!

Primary keys uniquely identify a row in a table. That is the relational database theory definition of a primary key. It is the column, or combination of columns, that uniquely identify each row. To facilitate this, when your create a Primary Key constraint, Oracle creates a UNIQUE index and also disallows NULL values. This is a further definition of the Primary Key. Unique values that cannot be NULL. Instead of creating a PK constraint, you can implement the same thing yourself by creating a UNIQUE constraint with a NOT NULL constraint. They both work equally as well.

You could use just a UNIQUE index, but that allows NULL values. And you can have multiple rows with NULL values. Therefore, you can't uniquely identify those rows. That's why just a UNIQUE index does not satisfy a PK constraint.

For More Information

  • What do you think about this answer? E-mail the editors at editor@searchDatabase.com with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
  • Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
  • Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.

This was last published in April 2002

Dig Deeper on Oracle database design and architecture

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.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close