Find tables without primary keys (PKs) in Db2 database

Query below lists tables in a database without primary keys.

Query

select tab.tabschema as schema_name,
    tab.tabname as table_name
from syscat.tables tab
left outer join syscat.tabconst const 
    on const.tabschema = tab.tabschema 
    and const.tabname = tab.tabname and const.type = 'P'
where 
    tab.type = 'T'
    and tab.tabschema not like 'SYS%'
    and const.constname is null

Columns

  • schema_name - schema name
  • table_name - table name

Rows

  • One row represents one table in a database
  • Scope of rows: all tables without primary keys in a database
  • Ordered by schema, table name

Sample results

Below is a list of tables in Microsoft System Center Configuration Manager database without primary keys. Is that a lot? Check out here.

0
There are no comments. Click here to write the first comment.