Skip to content

Commit 0ae793d

Browse files
authored
Merge pull request #2298 from BrentOzarULTD/2285_sp_BlitzIndex_datatype_sizes
@2285 sp_BlitzIndex fixing datatype sizes
2 parents f38de39 + b45b04e commit 0ae793d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

sp_BlitzIndex.sql

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ BEGIN TRY
11201120
is_replicated, is_sparse, is_filestream, seed_value, increment_value, last_value, is_not_for_replication )
11211121
EXEC sp_executesql @dsql;
11221122

1123+
11231124
--insert columns for nonclustered indexes
11241125
--this uses a full join to sys.index_columns
11251126
--We don't collect info on identity columns here. They may be in NC indexes, but we just analyze identities in the base table.
@@ -1915,7 +1916,15 @@ UPDATE #IndexSanity
19151916
SET key_column_names = D1.key_column_names
19161917
FROM #IndexSanity si
19171918
CROSS APPLY ( SELECT RTRIM(STUFF( (SELECT N', ' + c.column_name
1918-
+ N' {' + system_type_name + N' ' + CAST(max_length AS NVARCHAR(50)) + N'}'
1919+
+ N' {' + system_type_name + N' ' +
1920+
CASE max_length WHEN -1 THEN N'(max)' ELSE
1921+
CASE
1922+
WHEN system_type_name IN (N'char',N'varchar',N'binary',N'varbinary') THEN N'(' + CAST(max_length AS NVARCHAR(20)) + N')'
1923+
WHEN system_type_name IN (N'nchar',N'nvarchar') THEN N'(' + CAST(max_length/2 AS NVARCHAR(20)) + N')'
1924+
ELSE ''
1925+
END
1926+
END
1927+
+ N'}'
19191928
AS col_definition
19201929
FROM #IndexColumns c
19211930
WHERE c.database_id= si.database_id
@@ -1951,8 +1960,16 @@ FROM #IndexSanity si
19511960
WHEN 1 THEN N' DESC'
19521961
ELSE N''
19531962
END
1954-
+ N' {' + system_type_name + N' ' + CAST(max_length AS NVARCHAR(50)) + N'}'
1955-
AS col_definition
1963+
+ N' {' + system_type_name + N' ' +
1964+
CASE max_length WHEN -1 THEN N'(max)' ELSE
1965+
CASE
1966+
WHEN system_type_name IN (N'char',N'varchar',N'binary',N'varbinary') THEN N'(' + CAST(max_length AS NVARCHAR(20)) + N')'
1967+
WHEN system_type_name IN (N'nchar',N'nvarchar') THEN N'(' + CAST(max_length/2 AS NVARCHAR(20)) + N')'
1968+
ELSE ''
1969+
END
1970+
END
1971+
+ N'}'
1972+
AS col_definition
19561973
FROM #IndexColumns c
19571974
WHERE c.database_id= si.database_id
19581975
AND c.schema_name = si.schema_name

0 commit comments

Comments
 (0)