How do I list all tables WITHOUT a primary key?

June 7, 2008

Run the following SQL code:

SELECT T.TABLE_NAME AS “Tables without PKs”
FROM INFORMATION_SCHEMA.TABLES AS T
WHERE NOT EXISTS
(SELECT *
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC
WHERE CONSTRAINT_TYPE = ‘PRIMARY KEY’
AND T.TABLE_NAME = TC.TABLE_NAME)
AND T.TABLE_TYPE = ‘BASE TABLE’

Entry Filed under: SQL Scripts. Tags: , , , , , , , , , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

June 2008
M T W T F S S
    Jul »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Recent Posts

Archives

Blog Stats