Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find all indexes and their columns for tables, views and synonyms in oracle

Tags:

oracle

I jotted down the following query which will list the index name and its columns for a particular table:

select  b.uniqueness, a.index_name, a.table_name, a.column_name  from all_ind_columns a, all_indexes b where a.index_name=b.index_name  and a.table_name = upper('table_name') order by a.table_name, a.index_name, a.column_position; 

I want to modify this so that if I pass in a view or synonym also it works. Our system has variations of views, synonyms so it will be really helpful to have one query to which i can just supply the name (be it view synonym or table) and it would spit out the indexes and their columns.

like image 581
john Avatar asked Jun 10 '10 20:06

john


People also ask

Can you find out the indexes for a table in Oracle?

To show indexes for a particular table in Oracle use the following command: select index_name from dba_indexes where table_name='tablename';

How can you see all indexes defined for a table?

To see indexes for all tables within a specific schema you can use the STATISTICS table from INFORMATION_SCHEMA: SELECT DISTINCT TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA. STATISTICS WHERE TABLE_SCHEMA = 'your_schema'; Removing the where clause will show you all indexes in all schemas.

How do I know which columns have an index in a table?

ALL_IND_COLUMNS describes the columns of indexes on all tables accessible to the current user. Note: For join indexes, the TABLE_NAME and TABLE_OWNER columns in this view may not match the TABLE_NAME and TABLE_OWNER columns you find in the *_INDEXES (and other similar) data dictionary views.

Do views have indexes in Oracle?

Oracle SQL standards do not support creating indexes on views. If you need to index documents whose contents are in different tables, you can create a data storage preference using the USER_DATASTORE object.


1 Answers

Your query should work for synonyms as well as the tables. However, you seem to expect indexes on views where there are not. Maybe is it materialized views ?

like image 57
N. Gasparotto Avatar answered Oct 12 '22 19:10

N. Gasparotto