Solved

Oracle Primary Key, Unique Key, Unique Index Precedence

Posted on 2011-03-19
5
631 Views
Last Modified: 2013-12-07
Whan a Oracle table has a Primary Key, and also has a Unique Key and/or Unique Index defined that has more columns that the Primary Key, Which will dominate and under what conditions? Please do not tell me that this cannot be, nor that this is an Error. The instance I am currently working on has such Oracle tables. If this is an unreasonable poiint assignment please advise so I can correct.
Thanks,
Bill
0
Comment
Question by:pendlewe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 125 total points
ID: 35172658
It depends on the columns used in the query.

If you select the PK columns and only those columns, it will favor the PK.  If you use other columns in your Unique index, Oracle  will likely  favor it.

It is based on the statistics the optimizer has to go with at the time.
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 125 total points
ID: 35174054
Statistics aren't the only criteria.

If you need to check for null values, those might not be in your indexes, so neither PK or UK indexes would be used then.

Also note, in addition to the where clause, look at the columns being selected as well.

If your entire query can be satisfied by looking only at the data in the index that index might be used even if there is a PK lookup for direct access to the table.
0
 

Author Comment

by:pendlewe
ID: 35176549
The final process will update and/or delete, and/or insert records based on table uniqueness, and usie dynamic sqa to automate processing involving > 1000 different tables. You are correct, I had not thought about table uniqueness containing nullable columns.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 36032409
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question