SQL-Server-First-Responder-Kit icon indicating copy to clipboard operation
SQL-Server-First-Responder-Kit copied to clipboard

sp_BlitzIndex - add check for heaps with primary keys

Open BrentOzar opened this issue 11 years ago • 1 comments

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'

BrentOzar avatar Jun 08 '15 15:06 BrentOzar

#430

BlitzErik avatar Aug 26 '16 14:08 BlitzErik