If you are performing a database audit and want to quickly find out the tables not having a primary key, use this query :
USE [Your DB]
SELECT TABLE_SCHEMA as 'SCHEMA', TABLE_NAME as 'NO_Primary_Key'
TABLE_NAME NOT IN
( SELECT TABLE_NAME
WHERE CONSTRAINT_TYPE = 'PRIMARY KEY'
) AND TABLE_TYPE = 'BASE TABLE'
Did you like this post?
|subscribe via rss||subscribe via e-mail|
|print this post||follow me on twitter|