O'Reilly logo

Oracle SQL*Plus: The Definitive Guide by Jonathan Gennick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Indexes

Two views return information about indexes. Each index gets an entry in the ALL_INDEXES view, and the ALL_IND_COLUMNS view returns the columns included in each index.

Listing Indexes for a Table

The problem of listing indexes for a table is much the same as that of listing constraints on a table. You have a master-detail relationship between the index and its columns, and you may have multiple indexes on one table. There are two approaches you can take. One approach is to write a script that describes one particular index, while the other is to write a script that lists all indexes on a table.

The tradeoff between these two approaches is that one lets you look at indexes by name, while the other lets you look at indexes by table. The problem is that you probably need both ways. Sometimes, as when a unique index is violated, you do need to look up an index by name. Other times, you just want to see what indexes have been defined on a particular table.

One thing to keep in mind when working with unique indexes is that Oracle will report a unique index violation as if it were a constraint violation. The error message you get is the same as the one used when you violate a unique constraint, and it looks like this:

ORA-00001: unique constraint (JEFF.UNIQUE_BILLING_RATE) violated

The reason for this is no doubt because Oracle enforces both unique and primary key constraints by creating indexes on the constrained fields. If you do get the error message just shown, there are two ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required