List most referenced tables (by FK) in Teradata

This query shows tables referenced by foreign keys with number of this references.

See also:

Query

SELECT ParentDB || '.' || ParentTable AS TableName,
       COUNT(*) AS NumberOfReferences,
       COUNT(DISTINCT ChildDB || '.' || ChildTable) AS ReferencingTables
FROM    DBC.All_RI_ParentsV
GROUP BY    TableName
ORDER BY    NumberOfReferences DESC;

Columns

  • TableName - table name with database name
  • NumberOfReferences - references to this table
  • ReferencingTables - number of references to this table from diffrent tables

Rows

  • One row represents one table
  • Scope of rows: all tables that have at least one reference
  • Ordered by number of references descending

Sample results