Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle Primary Key, Unique Key, Unique Index Precedence

Posted on 2011-03-19
5
Medium Priority
?
636 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 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 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 500 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 71

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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 …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the 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…

916 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