IBM DB2 Query Toolbox - List tables with most foreign keys



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

IBM Db2 Query Toolbox - List tables with most foreign keys

A consulta abaixo lista as tabelas com seu número de chaves estrangeiras e o número de tabelas às quais se referem.
Query below lists tables with their number of foreign keys and number of tables they refer to.

Consulta - Query

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

Colunas

  • tabela - tabela com nome de esquema
  • Foreign_keys - número de chaves estrangeiras em uma tabela
  • referenced_tables - número de tabelas referenciadas.
    Observe que não é o mesmo que o número de chaves estrangeiras, pois várias chaves estrangeiras podem fazer referência à mesma tabela.

Linhas

  • Uma linha representa uma tabela em um banco de dados
  • Escopo das linhas: tabelas em um banco de dados que possuem chaves estrangeiras (referência a outras tabelas)
  • Ordenado por número de chaves estrangeiras daquelas com mais

Columns

  • table - table with schema name
  • foreign_keys - number of foreign keys in a table
  • referenced_tables - number of referenced tables.
    Note that it is not the same as number of foreign keys, as multiple foreign keys may reference the same table.

Rows

  • One row represents one table in a database
  • Scope of rows: tables in a database that have foreign keys (reference other tables)
  • Ordered by number of foreign keys from the ones with the most

Resultado - Sample results

Tabelas no GSDB com a maioria das chaves estrangeiras:
Tables in GSDB with most foreign keys:


Copyright © Dataedo.