IBM DB2 Query Toolbox - List unique indexes in the Db2 database



Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

IBM Db2 Query Toolbox - List unique indexes in the Db2 database

A consulta abaixo lista todos os índices exclusivos no banco de dados.
Query below lists all unique indexes in the database.

Consulta - Query

SELECT IND.INDNAME AS INDEX_NAME
,      IND.TABSCHEMA CONCAT '.' CONCAT IND.TABNAME AS TABLE
,      IND.IID AS INDEX_ID
,      CASE IND.UNIQUERULE 
            WHEN 'P' THEN 'PRIMARY KEY'
            WHEN 'U' THEN 'UNIQUE'
       END AS TYPE
,      LISTAGG(COLS.COLNAME, ', ')
            WITHIN GROUP (ORDER BY COLS.COLNAME) AS COLUMNS
,      CASE IND.INDEXTYPE
            when 'BLOK' then 'Block index'
            when 'REG' then 'Regular index'
            when 'CPMA' then 'Page map index for a column-organized table'
            when 'RCT ' then 'Key sequence index for a range-clustered table'
            when 'CLUS' then 'Clustering index'
            when 'TEXT' then 'Text index'
            when 'DIM' then 'Dimension block index'
            when 'XPTH' then 'XML path index'
            when 'XRGN' then 'XML region index'
            when 'XVIL' then 'Index over XML column (logical)'
            when 'XVIP' then 'Index over XML column (physical)'
       END AS INDEX_TYPE
  FROM SYSCAT.INDEXES IND
       JOIN SYSCAT.INDEXCOLUSE COLS
         ON IND.INDNAME = COLS.INDNAME
        AND IND.INDSCHEMA = COLS.INDSCHEMA
 WHERE IND.TABSCHEMA NOT LIKE 'SYS%'
   AND IND.UNIQUERULE != 'D'
 GROUP BY IND.INDNAME
 ,        IND.TABSCHEMA
 ,        IND.IID
 ,        IND.UNIQUERULE
 ,        IND.INDEXTYPE
 ,        IND.TABNAME
 ORDER BY TABLE
 ,        INDEX_ID;

Colunas

  • index_name - nome do índice
  • tabela - esquema e nome da tabela
  • index_id - id do índice (único na tabela)
  • modelo
    • CHAVE PRIMÁRIA
    • EXCLUSIVO
  • colunas - lista de colunas de índice separadas por ","
  • index_type:
    • Índice de bloco
    • Índice regular
    • Índice do mapa de página para uma tabela organizada por colunas
    • Índice de sequência de chaves para uma tabela agrupada por intervalo
    • Índice de agrupamento
    • Índice de texto
    • Índice de bloco de dimensão
    • Índice de caminho XML
    • Índice de região XML
    • Índice sobre coluna XML (lógico)
    • Índice sobre coluna XML (físico)

Linhas

  • Uma linha representa um índice único
  • Escopo das linhas: todos os índices únicos no banco de dados
  • Ordenado pelo esquema da tabela, nome da tabela e id do índice

Columns

  • index_name - index name
  • table - table schema and name
  • index_id - id of index (unique in table)
  • type
    • PRIMARY KEY
    • UNIQUE
  • columns - list of index columns separated with ","
  • index_type:
    • Block index
    • Regular index
    • Page map index for a column-organized table
    • Key sequence index for a range-clustered table
    • Clustering index
    • Text index
    • Dimension block index
    • XML path index
    • XML region index
    • Index over XML column (logical)
    • Index over XML column (physical)

Rows

  • One row represents one unique index
  • Scope of rows: all unique indexes in the database
  • Ordered by table schema, table name and index id

Resultado - Sample results


Copyright © Dataedo.