... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2005-02-04

Oracle

Here is an Oracle SQL statement that generates a DDL script to recreate all of the existing indexes:

select
  case when c.column_position=1
    then 'CREATE'||case when I.UNIQUENESS='UNIQUE' then ' UNIQUE' else '' end
        ||' INDEX '||I.INDEX_NAME||' ON '||I.TABLE_OWNER||'.'||I.TABLE_NAME||' ('
    else '' end,
  c.column_name,
  case when c.column_position <> all(
        select max(column_position) from user_ind_columns where index_name=i.index_name )
    then ', '
    else ');' end
from user_indexes i
, user_ind_columns c
where (c.index_name=i.index_name)

Blog Archive