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.
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.