In Oracle Database, you can find all indexes in a schema using Oracle data dictionary views such as USER_INDEXES, ALL_INDEXES, and DBA_INDEXES.
These views help Oracle DBAs identify index names, associated tables, index types, uniqueness, and index status.
In this tutorial, we will learn how to find all indexes in the current schema, a particular schema, and across the entire database with practical SQL examples.
1. Find All Indexes Using USER_INDEXES
If you want to find all indexes owned by your current schema, use the USER_INDEXES data dictionary view.
Execute the following query:
SELECT
INDEX_NAME,
TABLE_NAME,
INDEX_TYPE,
UNIQUENESS,
STATUS
FROM USER_INDEXES
ORDER BY TABLE_NAME;
Example Output
| INDEX_NAME | TABLE_NAME | INDEX_TYPE | UNIQUENESS | STATUS |
|---|---|---|---|---|
| IDX_EMP_ID | EMPLOYEE | NORMAL | UNIQUE | VALID |
| IDX_EMP_NAME | EMPLOYEE | NORMAL | NONUNIQUE | VALID |
| IDX_DEPT_ID | DEPARTMENT | NORMAL | NONUNIQUE | VALID |
Important Columns
- INDEX_NAME: Name of the index.
- TABLE_NAME: Name of the table associated with the index.
- INDEX_TYPE: Type of the index, such as NORMAL or BITMAP.
- UNIQUENESS: Indicates whether the index is UNIQUE or NONUNIQUE.
- STATUS: Indicates the index status, such as VALID or UNUSABLE.
2. Find Indexes Using ALL_INDEXES
If you want to find indexes belonging to a particular schema or other schemas accessible to your current user, use ALL_INDEXES.
For example, to find all indexes in the HR schema:
SELECT
OWNER,
INDEX_NAME,
TABLE_NAME,
INDEX_TYPE,
UNIQUENESS,
STATUS
FROM ALL_INDEXES
WHERE OWNER = 'HR'
ORDER BY TABLE_NAME;
Here, HR is the schema name.
Find Indexes for Multiple Schemas
You can also use the IN operator to find indexes belonging to multiple schemas:
SELECT
OWNER,
INDEX_NAME,
TABLE_NAME,
INDEX_TYPE,
UNIQUENESS,
STATUS
FROM ALL_INDEXES
WHERE OWNER IN ('HR', 'SCOTT', 'OE')
ORDER BY OWNER, TABLE_NAME;
3. Find All Indexes Using DBA_INDEXES
If you have the necessary DBA privileges and want to find indexes across the entire database, use DBA_INDEXES.
Execute the following query:
SELECT
OWNER,
INDEX_NAME,
TABLE_NAME,
INDEX_TYPE,
UNIQUENESS,
STATUS
FROM DBA_INDEXES
ORDER BY OWNER, TABLE_NAME;
This query displays indexes belonging to different schemas across the database.
Find Indexes for a Particular Schema Using DBA_INDEXES
SELECT
OWNER,
INDEX_NAME,
TABLE_NAME,
INDEX_TYPE,
UNIQUENESS,
STATUS
FROM DBA_INDEXES
WHERE OWNER = 'HR'
ORDER BY TABLE_NAME;
4. Find All Indexes on a Particular Table
If you want to find all indexes created on a specific table, use the USER_INDEXES view.
For example, to find all indexes on the EMPLOYEE table:
SELECT
INDEX_NAME,
TABLE_NAME,
UNIQUENESS,
STATUS
FROM USER_INDEXES
WHERE TABLE_NAME = 'EMPLOYEE';
If the table belongs to another accessible schema, use ALL_INDEXES:
SELECT
OWNER,
INDEX_NAME,
TABLE_NAME,
UNIQUENESS,
STATUS
FROM ALL_INDEXES
WHERE OWNER = 'HR'
AND TABLE_NAME = 'EMPLOYEE';
5. Difference Between USER_INDEXES, ALL_INDEXES and DBA_INDEXES
| View | Description |
|---|---|
| USER_INDEXES | Shows indexes owned by the current user. |
| ALL_INDEXES | Shows indexes accessible to the current user. |
| DBA_INDEXES | Shows indexes across the database, subject to appropriate privileges. |
6. Oracle Index Interview Question
Question: How do you find all indexes in a particular schema in Oracle?
I use the ALL_INDEXES data dictionary view with the OWNER condition to find all indexes belonging to a particular schema.
For example, to find all indexes in the HR schema:
SELECT *
FROM ALL_INDEXES
WHERE OWNER = 'HR';
7. Important Points to Remember
- USER_INDEXES: Displays indexes owned by the current schema.
- ALL_INDEXES: Displays indexes accessible to the current user.
- DBA_INDEXES: Displays indexes across the database with appropriate privileges.
- Use the OWNER column to filter indexes by schema.
- Use the TABLE_NAME column to find indexes on a particular table.
- Use the STATUS column to identify valid and unusable indexes.
- Use the UNIQUENESS column to identify unique and nonunique indexes.
Conclusion
Oracle provides several data dictionary views to find indexes in a database.
Depending on your requirement, you can use:
- USER_INDEXES to find indexes in your current schema.
- ALL_INDEXES to find indexes accessible to your user.
- DBA_INDEXES to find indexes across the entire database.
Understanding these dictionary views is very useful for Oracle DBAs, developers, and database performance tuning professionals.
Related Oracle DBA Topics:
- How to Check Index Usage in Oracle
- How to Monitor Index Usage
- Oracle Index Types
- How to Find Index Columns in Oracle
- Oracle Index Rebuild
- Oracle DBA Interview Questions