Solved

Oracle Primary Key, Unique Key, Unique Index Precedence

Posted on 2011-03-19
5
629 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
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 69

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL trigger 5 32
MS SQL Conditional WHERE clause 3 36
how to tune the query 17 45
populate value based on what is selected in lov 2 27
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

679 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