IBM DB2 Query Toolbox - List table indexes in Db2 database



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

IBM Db2 Query Toolbox - List table indexes in Db2 database

A consulta abaixo lista os índices da tabela.
Query below lists table indexes.

Consulta - Query

SELECT TABSCHEMA CONCAT '.' CONCAT TABNAME AS TABLE
,      IID AS INDEX_ID
,      CASE UNIQUERULE 
            WHEN 'P' THEN 'Primary key'
            WHEN 'U' THEN 'Unique'
            WHEN 'D' THEN 'Nonunique'
       END AS  TYPE
,      INDNAME AS INDEX_NAME
,      REPLACE(SUBSTRING(COLNAMES,2,LENGTH(COLNAMES)),'+',',') AS COLUMNS
,      CASE INDEXTYPE 
            WHEN 'BLOK' THEN 'Block index'
            WHEN 'CLUS' THEN 'Clustering index'
            WHEN 'DIM'  THEN 'Dimension block index'
            WHEN 'REG'  THEN 'Regular 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 
 WHERE INDSCHEMA NOT LIKE 'SYS%'
 ORDER BY TABLE, INDEX_ID

Colunas

  • tabela - o nome do índice da tabela é definido para
  • index_id - id do índice (único na tabela)
  • modelo
    • Chave primária
    • Exclusivo
    • Não únicov
  • index_name - nome do índice
  • colunas - lista de colunas de índice separadas por "+"
  • index_type - tipo de índice:
    • Índice de bloco
    • Índice de agrupamento
    • Índice de bloco de dimensão
    • Índice regular
    • Í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 representa o índice
  • Escopo das linhas: todos os índices (únicos e não exclusivos) nos bancos de dados
  • Ordenado por esquema, nome da tabela, id do índice

Columns

  • table - name of table index is defined for
  • index_id - id of index (unique in table)
  • type
    • Primary key
    • Unique
    • Nonunique
  • index_name - index name
  • columns - list of index columns separated with "+"
  • index_type - index type:
    • Block index
    • Clustering index
    • Dimension block index
    • Regular index
    • XML path index
    • XML region index
    • Index over XML column (logical)
    • Index over XML column (physical)

Rows

  • One row represents represents index
  • Scope of rows: all indexes (unique and nonunique) in databases
  • Ordered by schema, table name, index id

Resultado - Sample results


Copyright © Dataedo.