IBM DB2 Query Toolbox - Find table that DON'T have a column with specific name



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

IBM Db2 Query Toolbox - Find table that DON'T have a column with specific name in Db2 database

Os bancos de dados costumam ter colunas padrão. Exemplos de tais colunas padrão pode ser id , MODIFIED_DATE , created_by ou row_version .
Databases often have standard columns. Examples of such standard columns can be id, modified_date, created_by or row_version.

A consulta abaixo encontra todas as tabelas que não possuem uma coluna 'MODIFIEDDATE'.
Query below finds all tables that do not have a 'MODIFIEDDATE' column.

Consulta - Query

SELECT T.TABSCHEMA AS SCHEMA_NAME
,      T.TABNAME AS TABLE_NAME
  FROM SYSCAT.TABLES T
       LEFT OUTER JOIN 
       (SELECT TABSCHEMA
       ,       TABNAME 
          FROM SYSCAT.COLUMNS 
         WHERE COLNAME ='MODIFIEDDATE'
       )C ON C.TABSCHEMA = T.TABSCHEMA AND C.TABNAME = T.TABNAME
 WHERE T.TYPE='T'
   AND C.TABNAME IS  NULL
 ORDER BY SCHEMA_NAME
 ,        TABLE_NAME

Colunas

  • schema_name - nome do esquema da tabela encontrada
  • table_name - nome da tabela encontrada

Linhas

  • Uma linha representa uma tabela
  • Escopo das linhas: todas as tabelas encontradas
  • Ordenado pelo nome do esquema

Columns

  • schema_name - name of schema of found table
  • table_name - name of found table

Rows

  • One row represents a table
  • Scope of rows: all found tables
  • Ordered by schema name

Resultado - Sample results

Essas tabelas não possuem uma coluna 'MODIFIEDDATE'.
These tables do not have a 'MODIFIEDDATE' column.


Copyright © Dataedo.