List most referenced tables in Vertica database (by FK)

Query below lists tables that are most referenced by other tables with foreign keys.

See also:

Query

select reference_table_schema || '.' || reference_table_name
            as table,
       count(*) as references,
       count(distinct table_schema ||'.'|| table_name) as referencing_tables
from v_catalog.foreign_keys
group by reference_table_schema,
         reference_table_name
order by reference_table_schema,
         reference_table_name;

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 references descending

Sample results