T-SQL Script: Find tables with no clustered index (HEAPs)
T-SQL Script: Find tables with no clustered index (HEAPs)
SELECT
t.name AS TableName,
s.name AS SchemaName
FROM sys.tables t
JOIN sys.schemas s ON t.schema_id = s.schema_id
LEFT JOIN sys.indexes i
ON t.object_id = i.object_id
AND i.type = 1
WHERE i.object_id IS NULL
ORDER BY s.name, t.name;
t.name AS TableName,
s.name AS SchemaName
FROM sys.tables t
JOIN sys.schemas s ON t.schema_id = s.schema_id
LEFT JOIN sys.indexes i
ON t.object_id = i.object_id
AND i.type = 1
WHERE i.object_id IS NULL
ORDER BY s.name, t.name;