Tables with no Primary and Foreign keys

John Paul Cook has posted in his blog to show the list of tables that have no Referential Integrity.

What if you want to know list of tables that have no primary and foreign keys?

Here is the query

select
        table_name
from 
        INFORMATION_SCHEMA.TABLES
where 
        objectproperty(object_id(table_name),'TableHasForeignKey')=0 AND 
        objectproperty(object_id(table_name),'TableHasPrimaryKey')=0 AND 
        table_type
='BASE TABLE'
order by 
        table_name

 

Published 10 April 2009 15:35 by Madhivanan

Comments

No Comments