Re: getting DDL for all indexes on a table (using dbms_metadata.get)

From: Mark D Powell <Mark.Powell_at_eds.com>
Date: Tue, 20 May 2008 13:49:23 -0700 (PDT)
Message-ID: <2ed0df81-b1b3-4cd2-a689-cd8e6f4304f6@l28g2000prd.googlegroups.com>


On May 20, 4:10 pm, GS <G..._at_GS.com> wrote:
> A table in a database has 146 columns and 76 indexes on it, most of the
> indexes are unused, I suspect.  I'm not sure why, but most of these were
> (likely) from when developers had access to the database and were adding
> an index everytime they thought it might do some good.  I want see which
> of these are being used at all, and drop the ones that aren't, but I
> want to generate the DDL for all the indexes on the table  so if need be
> I can restore them.
>
> I used to use a tool (I think it was called DB Artisan or something like
> that) that would do this, but don't have it available anymore and in any
> case would just as soon learn the sql syntax for doing this. I have done
> some research on dbms_metadata.get and see how I can generate ddl for a
> specific table, but I want it to generate all the ddl for all indexes on
> a given table, is this possible?
>
> database is 9.2.0.7
>
> thanks in advance

I have never used the routine but look at the dbms_metadata procedure GET_DEPENDENT_DDL. It would be fairly simple using SQL to generate a series of dbms_metadata.get_ddl calls where each call generated an index for the table_name used in the driving query against dba_indexes.

We wrote our own index code generator years ago that just reads dba_indexes and dba_ind_columns that works for regular non-partitioned indexes and we have stuck to it. I have written a few scripts that use dbms_metadata but not the all indexes for a table yet.

HTH -- Mark D Powell -- Received on Tue May 20 2008 - 15:49:23 CDT

Original text of this message