0
(0)

Below query can be used to get list of tables without having primary key in SQL Server.

use DBNAME /** replace your database name here **/
go
select s.[name] + N'.' + t.[name] [Table]
from sys.tables t
inner join sys.schemas s on t.[schema_id] = s.[schema_id]
where not exists
( select * from sys.key_constraints kc
where kc.[type] = N'PK' and kc.parent_object_id = t.[object_id]
);

Output:

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.