List all tables refrenced by specific table (by FK) in Db2 database

Query below lists all tables refrenced with foregin key by specific table.

Query

select tabschema  || '.' || tabname as foreign_table,
       '>-' as rel,
       reftabschema || '.' || reftabname as primary_table
from syscat.references
where tabname = 'PROJECT'
      -- and tabschema = 'ADMINISTRATOR' -- put your schema name here
order by foreign_table,
         primary_table

Columns

  • foreign_table - foreign table name with schema name - the table you provided as a parameter
  • foreign_table - relationship symbol implicating FK and direction
  • primary_table - primary (rerefenced) tables names with schema name - the tables you are looking for

Rows

  • One row represents one referenced table
  • Scope of rows: all tables referenced by table with provided name (and optionally schema)
  • Ordered by referenced table schema and name

Notes

  • There can be more tables with the same name. If that's the case, uncomment where clause and provide schema name

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.