Jan 5, 2014

Sql query for list out all tables which has not any primary key in sql server


Write a sql query or script to get or list out all tables in a database which has not any primary key in sql server

SELECT name 
FROM sys.tables
WHERE  NOT EXISTS(SELECT  1 
   FROM  sys.indexes
   WHERE  t.object_id = i.object_id 
     AND is_primary_key = 1)

No comments:

Post a Comment