IBM DB2 Query Toolbox - Find tables without foreign keys in Db2 database



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

IBM Db2 Query Toolbox - Find tables without foreign keys in Db2 database

A consulta abaixo lista todas as tabelas que não possuem chaves estrangeiras.
Query below lists all tables that do not have foreign keys.

Consulta - Query

SELECT TAB.TABSCHEMA AS SCHEMA_NAME
,      TAB.TABNAME AS TABLE_NAME
,      '>- NO FKS' FOREIGN_KEYS
  FROM SYSCAT.TABLES TAB
       LEFT JOIN SYSCAT.TABCONST CONST 
            ON CONST.TABSCHEMA = TAB.TABSCHEMA 
           AND CONST.TABNAME = TAB.TABNAME 
           AND CONST.TYPE = 'F'
 WHERE TAB.TYPE = 'T'
   AND TAB.TABSCHEMA NOT LIKE 'SYS%'
   AND CONST.CONSTNAME IS NULL

Colunas

  • schema_name - nome do esquema da tabela
  • table_name - nome da tabela
  • Foreign_keys - símbolo indicando falta de FKs

Linhas

  • Uma linha representa uma tabela que não tem uma chave estrangeira
  • Escopo das linhas: todas as tabelas em um banco de dados que não possuem chaves estrangeiras (não se referem a outras tabelas)
  • Ordenado por esquema e nome de tabela

Columns

  • schema_name - table schema name
  • table_name - table name
  • foreign_keys - symbol indicating lack of FKs

Rows

  • One row represents one table that doesn't have a foreign key
  • Scope of rows: all tables in a database that don't have foreign keys (do not refer to other tables)
  • Ordered by schema and table name

Resultado - Sample results

Lista de tabelas em SAMPLE sem chaves estrangeiras:
List of tables in SAMPLE without foreign keys:


Copyright © Dataedo.