Tables without a Clustered Index (Heap)

List all SQL server table that do not have primary key

SELECT [Table] = s.[Name] + N'.' + t.[Name] 
FROM [sys].tables t
   INNER JOIN [sys].schemas s 
	 ON t.[schema_id] = s.[schema_id]
WHERE NOT EXISTS
(
   SELECT 1 FROM [sys].indexes i
   WHERE i.[object_id] = t.[object_id]
   AND i.index_id = 1
);
--You can easily find the tables with Clustered indexes by just using EXISTS in the WHERE clause.
Spread the love

1 thought on “Tables without a Clustered Index (Heap)”

  1. Pingback: How to find the missing foreign key indexes Himanshu Patel SQL Server Consultant developer & Administrator -

Leave a Comment