IBM DB2 Query Toolbox - Find tables that are not referenced by the foreign keys



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

IBM Db2 Query Toolbox - Find tables that are not referenced by the foreign keys

A consulta abaixo lista as tabelas que não são referenciadas pelas chaves estrangeiras.
Query below lists tables that are not referenced by the foreign keys.

Consulta - Query

SELECT 'NO FKS >-' FOREIGN_KEYS
,      TAB.TABSCHEMA AS SCHEMA_NAME
,      TAB.TABNAME AS TABLE_NAME
  FROM SYSCAT.TABLES TAB
       LEFT OUTER JOIN SYSCAT.REFERENCES REF
            ON REF.REFTABSCHEMA = TAB.TABSCHEMA
           AND REF.REFTABNAME = TAB.TABNAME
 WHERE TAB.TYPE = 'T'
   AND TAB.TABSCHEMA NOT LIKE 'SYS%'
   AND REF.CONSTNAME IS NULL     
 ORDER BY TAB.TABSCHEMA, TAB.TABNAME

Colunas

  • Foreign_keys - símbolo indicando falta de referências FK
  • schema_name - nome do esquema da tabela
  • table_name - nome da tabela

Linhas

  • Uma linha representa uma mesa
  • Escopo das linhas: todas as tabelas em um banco de dados que não são referenciadas pelas chaves estrangeiras
  • Ordenado por esquema, nome da tabela

Columns

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

Rows

  • One row represents one table
  • Scope of rows: all tables in a database that are not referenced by the foreign keys
  • Ordered by schema, table name

Resultado - Sample results

Lista de tabelas em AdventureWorks não referenciadas por chaves estrangeiras:
List of tables in AdventureWorks not referenced by foreign keys:


Copyright © Dataedo.