Find tables without relationships - Loner Tables - in Db2 database

This query listed tables that have no foreign keys, meaning they are not referencing any table or are not on the "many" side of FK.

Query below lists something a little different - tables that are not referencing and are not referenced by other tables. Something I called Loner Tables. This diagram illustrates the concept:

Learn more about Loner Tables


select 'No FKs >-' refs,
    tab.tabschema concat '.' concat tab.tabname as table, 
    '>- no FKs' fks
syscat.tables tab
left outer join syscat.tabconst const 
    on const.tabschema = tab.tabschema 
    and const.tabname = tab.tabname and const.type ='F'
left outer join syscat.references ref 
    on ref.reftabschema = tab.tabschema  and ref.reftabname = tab.tabname 
    tab.type ='T'
    and tab.tabschema not like 'SYS%'
    and const.constname is null
    and ref.constname is null


  • refs - icon symbolizing lack of references by foregin key
  • table - name of the table with schema name
  • fks - icon symbolizing lack of foregin key constraints


  • One row represents one table
  • Scope of rows: tables that are not related (not refererencing and not being referenced with foreign key constraints) with any table
  • Ordered by schema table name

Sample results

Loner Tables in GSDB:

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