List foreign keys in Db2 database

Query below returns foreign key constrants defined in a database.

Query

select 
    ref.tabschema  concat '.' concat ref.tabname as foreign_table,
    '>-' as rel,
    ref.reftabschema concat '.' concat ref.reftabname as primary_table,
    ref.constname as fk_constraint_name
from syscat.references ref
order by foreign_table, primary_table

Columns

  • foreign_table - foreign table name with schema name
  • rel - relationship symbol implicating direction
  • primary_table - primary (rerefenced) table name with schema name
  • fk_constraint_name - foreign key constraint name

Rows

  • One row represents one foreign key. If foreign key consists of multiple columns (composite key) it is still represented as one row.
  • Scope of rows: all foregin keys in a database
  • Ordered by foreign table schema name and table name

Sample results

Foreign keys in Sample database:

You could also get this

Get this interactive HTML data dictionary in minutes with Dataedo.

See live HTML data dictionary sample

Try for free