Skip to content

Commit 37e8b1c

Browse files
alchemistmattBrentOzar
authored andcommitted
#1988 sp_BlitzIndex INSERT column order bug (#1989)
* #1952 sp_BlitzIndex Fix INSERT query column order * #1988 sp_BlitzIndex Update the column order of the INSERT statement and SELECT items to match the CREATE TABLE statement Move columns Drop_Tsql and Create_Tsql to after index_name for consistency with the CREATE TABLE statement
1 parent ed6b487 commit 37e8b1c

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

sp_BlitzIndex.sql

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,8 +4637,6 @@ BEGIN;
46374637
[create_date],
46384638
[modify_date],
46394639
[more_info],
4640-
[Drop_Tsql],
4641-
[Create_Tsql],
46424640
[display_order]
46434641
)
46444642
SELECT ''@@@RunID@@@'',
@@ -4650,6 +4648,18 @@ BEGIN;
46504648
i.[schema_name] AS [Schema Name],
46514649
i.[object_name] AS [Object Name],
46524650
ISNULL(i.index_name, '''') AS [Index Name],
4651+
CASE
4652+
WHEN i.is_primary_key = 1 AND i.index_definition <> ''[HEAP]''
4653+
THEN N''-ALTER TABLE '' + QUOTENAME(i.[schema_name]) + N''.'' + QUOTENAME(i.[object_name]) +
4654+
N'' DROP CONSTRAINT '' + QUOTENAME(i.index_name) + N'';''
4655+
WHEN i.is_primary_key = 0 AND i.index_definition <> ''[HEAP]''
4656+
THEN N''--DROP INDEX ''+ QUOTENAME(i.index_name) + N'' ON '' +
4657+
QUOTENAME(i.[schema_name]) + N''.'' + QUOTENAME(i.[object_name]) + N'';''
4658+
ELSE N''''
4659+
END AS [Drop TSQL],
4660+
CASE
4661+
WHEN i.index_definition = ''[HEAP]'' THEN N''''
4662+
ELSE N''--'' + ict.create_tsql END AS [Create TSQL],
46534663
CAST(i.index_id AS NVARCHAR(10))AS [Index ID],
46544664
db_schema_object_indexid AS [Details: schema.table.index(indexid)],
46554665
CASE WHEN index_id IN ( 1, 0 ) THEN ''TABLE''
@@ -4712,18 +4722,6 @@ BEGIN;
47124722
i.create_date AS [Create Date],
47134723
i.modify_date AS [Modify Date],
47144724
more_info AS [More Info],
4715-
CASE
4716-
WHEN i.is_primary_key = 1 AND i.index_definition <> ''[HEAP]''
4717-
THEN N''-ALTER TABLE '' + QUOTENAME(i.[schema_name]) + N''.'' + QUOTENAME(i.[object_name]) +
4718-
N'' DROP CONSTRAINT '' + QUOTENAME(i.index_name) + N'';''
4719-
WHEN i.is_primary_key = 0 AND i.index_definition <> ''[HEAP]''
4720-
THEN N''--DROP INDEX ''+ QUOTENAME(i.index_name) + N'' ON '' +
4721-
QUOTENAME(i.[schema_name]) + N''.'' + QUOTENAME(i.[object_name]) + N'';''
4722-
ELSE N''''
4723-
END AS [Drop TSQL],
4724-
CASE
4725-
WHEN i.index_definition = ''[HEAP]'' THEN N''''
4726-
ELSE N''--'' + ict.create_tsql END AS [Create TSQL],
47274725
1 AS [Display Order]
47284726
FROM #IndexSanity AS i
47294727
LEFT JOIN #IndexSanitySize AS sz ON i.index_sanity_id = sz.index_sanity_id

0 commit comments

Comments
 (0)