Query below returns foreign key constrants defined in a database.
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
- 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
- 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
Foreign keys in Sample database:
You could also get this
Get this interactive HTML data dictionary in minutes with Dataedo.