Default unique index on primary key. [message #656275] |
Sat, 01 October 2016 12:47  |
 |
dancko
Messages: 108 Registered: June 2013 Location: italy
|
Senior Member |
|
|
Hi to all,
I want ask why oracle creates a default unique index when we create a primary key on the some table?
Sorry for a interview question and probably trivial question but I'm not be able to find a response.
thanks in advance!
[Updated on: Sat, 01 October 2016 12:48] Report message to a moderator
|
|
|
|
|
|
|
Re: Default unique index on primary key. [message #656285 is a reply to message #656281] |
Sun, 02 October 2016 00:20   |
 |
Michel Cadot
Messages: 68737 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
dancko wrote on Sat, 01 October 2016 22:15thanks... but why we need to enforce the primary constraint with the unique index?
Is the primary key constraint not enough to enforce the integrity rows by itself?
1/ There is no need to have an index (unique or not), it is just the most efficient way to enforce it.
2/ A "primary key constraint" is just a declaration, like a column of type INTEGER, now you have to write some code which enforce them. In the case of the column, Oracle has to verify the data you insert is actually a number, in the case of the constraint, it has to verify that the data you insert is not already present in the table.
[Edit: typo]
[Updated on: Sun, 16 October 2016 13:43] Report message to a moderator
|
|
|
|