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
Solved

Oracle Primary Key, Unique Key, Unique Index Precedence

Posted on 2011-03-19
5
626 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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…

828 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