Find tables without primary keys (PKs)

The query below lists tables in a database without primary keys.


select schema_name(tab.schema_id) as [schema_name],
    tab.[name] as table_name
from sys.tables as tab
    left outer join sys.indexes as pk
        on tab.object_id = pk.object_id
        and pk.is_primary_key = 1
where pk.object_id is null
order by schema_name(tab.schema_id),


  • schema_name - name of the schema
  • table_name - name of the table


  • 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 without primary keys.

Is that a lot? Check out here.

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.