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

sp_BlitzIndex assumes that Primary Key is clustered and does not explicitly script it as such

Open rancourt-martin opened this issue 1 month ago • 4 comments

Version of the script SELECT @Version = '8.28', @VersionDate = '20251124';

What is the current behavior?

sp_BlitzIndex seems to assume that Primary Key is clustered for the "create tsql" and does not explicitly script it out when running the sp

If the current behavior is a bug, please provide the steps to reproduce.

run sp_blitzIndex @DatabaseName, @SchemaName, @TableName on a table that has a NONCLUSTERED Primary Key

What is the expected behavior?

ALTER TABLE [mydb].[dbo].[my_not_so_best_practice_table] ADD CONSTRAINT [xyz_constraint] PRIMARY KEY NONCLUSTERED

Which versions of SQL Server and which OS are affected by this issue? Did this work in previous versions of our procedures?

Microsoft SQL Server 2022 (RTM-CU21) (KB5065865) - 16.0.4215.2 (X64) Aug 11 2025 13:24:21 Copyright (C) 2022 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Datacenter 10.0 <X64> (Build 17763: ) (Hypervisor)

rancourt-martin avatar Dec 04 '25 22:12 rancourt-martin

oops, forgot, should read like the below: ALTER TABLE [dbo].[my_not_so_best_practice_table] ADD CONSTRAINT [constraint_xyz] PRIMARY KEY NONCLUSTERED ( [some_column] ASC )

rancourt-martin avatar Dec 05 '25 03:12 rancourt-martin

Sure, if that's important to you, we'd welcome a pull request to change that! Did you want to contribute that?

BrentOzar avatar Dec 05 '25 13:12 BrentOzar

yes, want to contribute for sure. pbly 2-3 weeks eta though.

rancourt-martin avatar Dec 05 '25 13:12 rancourt-martin

Totally fine! I'm heading out on vacation and won't be back to working on it until Jan anyway.

BrentOzar avatar Dec 05 '25 13:12 BrentOzar