IBM DB2 Query Toolbox - List table columns in Db2 database



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

IBM Db2 Query Toolbox - List table columns in Db2 database

A consulta abaixo lista todas as colunas da tabela em um banco de dados.
Query below lists all table columns in a database.

Consulta - Query

SELECT C.TABSCHEMA AS SCHEMA_NAME
,      C.TABNAME AS TABLE_NAME
,      C.COLNAME AS COLUMN_NAME
,      C.COLNO AS POSITION
,      C.TYPENAME AS DATA_TYPE
,      C.LENGTH
,      C.SCALE
,      C.REMARKS AS DESCRIPTION
,      CASE WHEN  C.NULLS = 'Y' THEN 1 ELSE 0 END AS NULLABLE
,      DEFAULT AS DEFAULT_VALUE
,      CASE WHEN C.IDENTITY ='Y' THEN 1 ELSE 0 END AS IS_IDENTITY
,      CASE WHEN C.GENERATED ='' THEN 0 ELSE 1 END AS  IS_COMPUTED
,      C.TEXT AS COMPUTED_FORMULA
  FROM SYSCAT.COLUMNS C
       INNER JOIN SYSCAT.TABLES T ON 
       T.TABSCHEMA = C.TABSCHEMA AND T.TABNAME = C.TABNAME
 WHERE T.TYPE = 'T'
 ORDER BY SCHEMA_NAME
 ,        TABLE_NAME

Colunas

  • schema_name - nome do esquema
  • view_name - nome da tabela
  • column_name - nome da coluna
  • posição - número desta coluna na tabela (começando com 0)
  • data_type - nome do tipo de dados
  • comprimento - comprimento máximo dos dados; 0 para tipos distintos.
  • escala:
    • escala se o tipo de coluna for DECIMAL,
    • número de dígitos de segundos fracionários se o tipo de coluna for TIMESTAMP,
    • 0 caso contrário
  • descrição - descrição da coluna
  • nullable - atributo nullability para a coluna
  • is_identity - atributo de identidade para a coluna
  • is_computed - atributo computado (gerado) para a coluna
  • computed_formula - o texto da expressão da coluna computada

Linhas

  • Uma linha representa uma coluna da tabela
  • Escopo das linhas: todas as colunas em todas as tabelas em um banco de dados
  • Ordenado por esquema, nome da tabela, id da coluna

Columns

  • schema_name - schema name
  • view_name - table name
  • column_name - column name
  • position - number of this column in the table (starting with 0)
  • data_type - name of the data typ
  • length - maximum length of the data; 0 for distinct types.
  • scale:
    • scale if the column type is DECIMAL,
    • number of digits of fractional seconds if the column type is TIMESTAMP,
    • 0 otherwise
  • description - description of column
  • nullable - nullability attribute for the column
  • is_identity - identity attribute for the column
  • is_computed - computed (generated) attribute for the column
  • computed_formula - the text of the computed column expression

Rows

  • One row represents one table column
  • Scope of rows: all columns in all tables in a database
  • Ordered by schema, table name, column id

Resultado - Sample results


Copyright © Dataedo.