Solved

Oracle Primary Key, Unique Key, Unique Index Precedence

Posted on 2011-03-19
5
622 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 76

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 73

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 68

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now