SQL-Server-First-Responder-Kit
SQL-Server-First-Responder-Kit copied to clipboard
sp_BlitzIndex - add check for heaps with primary keys
Had an app where all the tables were heaps, and there were PKs configured but somebody just didn't know they were supposed to be clustered. Script I used to find 'em:
SELECT SCHEMA_NAME(o.schema_id) AS schema_name, o.name AS table_name, i.type_desc, iPK.name AS primary_key_name FROM sys.objects o INNER JOIN sys.indexes i ON o.object_id = i.object_id AND i.index_id = 0 LEFT OUTER JOIN sys.indexes iPK ON o.object_id = iPK.object_id AND iPK.index_id <> 0 AND iPK.is_primary_key = 1 WHERE o.type = 'U'
#430