IBM DB2 Query Toolbox - List most referenced tables in Db2 database (by FK)



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

IBM Db2 Query Toolbox - List most referenced tables in Db2 database (by FK)

A consulta abaixo lista as tabelas mais referenciadas por outras tabelas com chaves estrangeiras.
Essas são as tabelas do dicionário, como país , produto ou pessoa.
Em data warehouses, essas são tabelas de dimensão.

Query below lists tables that are most referenced by other tables with foreign keys.
Those are the dictionary tables such as country, product or person.
In data warehouses those are dimension tables.

Consulta - Query

SELECT DISTINCT REFTABSCHEMA CONCAT '.' CONCAT REFTABNAME AS TABLE
,      COUNT(*) AS REFERENCES
,      COUNT(DISTINCT TABSCHEMA CONCAT '.' CONCAT TABNAME) AS REFERENCING_TABLES 
  FROM SYSCAT.REFERENCES
 GROUP BY REFTABSCHEMA CONCAT '.' CONCAT REFTABNAME
 ORDER BY REFERENCES DESC

Colunas

  • tabela - nome da tabela com o nome do esquema
  • referências - número de chaves estrangeiras que fazem referência a esta tabela
  • referencing_tables - número de tabelas diferentes que fazem referência a esta tabela

Linhas

  • Uma linha representa uma tabela em um banco de dados
  • Escopo das linhas: tabelas sendo usadas em chaves estrangeiras como tabela de chave primária
  • Ordenado por número decrescente de chaves anteriores

Columns

  • table - name of the table with schema name
  • references - number of foreign keys referencing to this table
  • referencing_tables - number of different tables referencing to this table

Rows

  • One row represents one table in a database
  • Scope of rows: tables being used in foreign keys as primary key table
  • Ordered by number of foregin keys descending

Resultado - Sample results

Lista das tabelas mais referenciadas no banco de dados GSDB.
A tabela GOSALESDW.GO_TIME_DIM é referenciada 13 vezes em 11 tabelas diferentes.

List of most referenced tables in GSDB database.
GOSALESDW.GO_TIME_DIM table is referenced 13 times from 11 different tables.


Copyright © Dataedo.