Home » RDBMS Server » Server Administration » Default unique index on primary key.
Default unique index on primary key. [message #656275] Sat, 01 October 2016 12:47 Go to next message
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 #656276 is a reply to message #656275] Sat, 01 October 2016 13:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
when all else fails Read The Fine Manual

https://docs.oracle.com/apps/search/search.jsp?category=database&product=e50529-01&q=primary+key

http://docs.oracle.com/database/121/CNCPT/datainte.htm#GUID-E1033BB9-0F67-4E59-82AC-B8B572FD82BB

http://docs.oracle.com/database/121/CNCPT/glossary.htm#GUID-8640EFA5-276C-4812-A078-1F21F55F4200
Re: Default unique index on primary key. [message #656279 is a reply to message #656275] Sat, 01 October 2016 14:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Because it is the fastest way to enforce this constraint.

Re: Default unique index on primary key. [message #656281 is a reply to message #656279] Sat, 01 October 2016 15:15 Go to previous messageGo to next message
dancko
Messages: 108
Registered: June 2013
Location: italy
Senior Member
thanks... 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?

[Updated on: Sat, 01 October 2016 15:19]

Report message to a moderator

Re: Default unique index on primary key. [message #656282 is a reply to message #656281] Sat, 01 October 2016 15:59 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
a non-unique INDEX can be used with PK constraint.
First CREATE INDEX & next CREATE CONSTRAINT

why do you ever create any index?
Re: Default unique index on primary key. [message #656285 is a reply to message #656281] Sun, 02 October 2016 00:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

dancko wrote on Sat, 01 October 2016 22:15
thanks... 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

Re: Default unique index on primary key. [message #656735 is a reply to message #656285] Sun, 16 October 2016 11:32 Go to previous message
dancko
Messages: 108
Registered: June 2013
Location: italy
Senior Member
thanks a lot to all.
Previous Topic: Connection failed from Oracle XE in Windows
Next Topic: alter table ... enable row movement
Goto Forum:
  


Current Time: Thu Mar 28 03:26:42 CDT 2024