How do I list all tables WITHOUT a primary key?
June 7, 2008 at 12:17 am Leave a comment
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’
Like this:
Be the first to like this post.
Entry filed under: SQL Scripts. Tags: constraints, INFORMATION_SCHEMA, key, list, PK, primary, primary key, tables, TABLE_CONTRAINTS, without.
How do I pad an Integer to 4 digits with leading zeros? How do I create and use a Synonym for a table in SQL Server 2005?
Trackback this post | Subscribe to the comments via RSS Feed