Find tables without foreign keys in Redshift

This query lists tables with lack of foreign keys.

See also:


select tab.table_schema,
       '>- no FKs' as foreign_keys
       from information_schema.tables tab
where tab.table_schema not in ('information_schema', 'pg_catalog') 
      and tab.table_type ='BASE TABLE'
      and tab.table_schema || '.' || tab.table_name not in
          (select distinct table_schema || '.' || table_name
           from information_schema.table_constraints
           where constraint_type = 'FOREIGN KEY')
order by tab.table_schema,


  • table_schema - name of the schema
  • table_name - name of the table
  • foreign_keys - symbol indicating lack of FKs


  • One row represents one table with lack of foreign keys
  • Scope of rows: all tables in a database that don't have foreign keys
  • Ordered by table schema and table name

Sample results

Tables without foreign keys:

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.