Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query-find table which have neither Primary nor Unique key

557703Jul 8 2011 — edited Jul 8 2011
hi ,

I am bit novice in query writing. But I need to list all those table in 9i database which have neither primary key nor Unique key constraints.

I use the follwing query to find the tables having either primary or unique key constraints ( atleast one)

select OWNER,TABLE_NAME from dba_constraints where CONSTRAINT_TYPE IN ('P','U')
and OWNER not in ('SYS','SYSTEM') order by OWNER, TABLE_NAME


Now to list those tables which have none of constraints either Primary or unique key constraints I could use

select OWNER,TABLE_NAME from dba_constraints where CONSTRAINT_TYPE NOT IN ('P','U')
and OWNER not in ('SYS','SYSTEM') order by OWNER, TABLE_NAME

but this query list large no of tables ( multile name for same tables as some tables has multilpe constraints other that PK , UK) how can I use 'distinct ' to list table name only once. I also need 'owner' in the query.

Thanx in advance.

Regards
Amit
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2011
Added on Jul 8 2011
5 comments
3,271 views