← Performance
Oracle · Performance
How to find tables without a primary key in Oracle
List Oracle tables that have no primary key constraint by joining DBA_TABLES with DBA_CONSTRAINTS.
Tested on11g12c18c19c21c23ai26ai
Left join DBA_TABLES against DBA_CONSTRAINTS filtered to constraint_type = P; NULL rows are tables with no primary key. Handy audit before enabling GoldenGate, materialized view replication, or any tool that relies on unique row identity.
SELECT t.owner AS schema_name,
t.table_name
FROM sys.dba_tables t
LEFT JOIN sys.dba_constraints c
ON t.owner = c.owner
AND t.table_name = c.table_name
AND c.constraint_type = 'P'
WHERE c.constraint_type IS NULL
ORDER BY t.owner, t.table_name;performanceintegrityprimary keydba_constraints