You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: QueryTemplates/Performance/index-fragmentation.sql
+11-4Lines changed: 11 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,17 @@ SELECT dbschemas.[name] as 'Schema',
6
6
FORMAT(AVG(indexstats.avg_fragmentation_in_percent), 'N2') AS avg_fragmentation_in_percent,
7
7
FORMAT(SUM(indexstats.page_count), 'N0') AS page_count,
8
8
'ALTER INDEX ['+dbindexes.[name]+'] ON ['+dbschemas.name+'].['+dbtables.[name]+'] REORGANIZE PARTITION = '
9
-
+ CASE WHEN EXISTS(SELECT TOP 11FROMsys.partition_schemes s WHEREs.data_space_id=dbindexes.data_space_id) THEN CAST(indexstats.partition_numberASVARCHAR(3)) ELSE 'ALL' END +';'AS CmdReorg,
9
+
+ CASE WHEN EXISTS(SELECT TOP 11FROMsys.partition_schemes s WHEREs.data_space_id=dbindexes.data_space_id)
10
+
THEN CAST(indexstats.partition_numberASVARCHAR(3)) ELSE 'ALL' END +';'AS CmdReorg,
10
11
'ALTER INDEX ['+dbindexes.[name]+'] ON ['+dbschemas.name+'].['+dbtables.[name]+'] REBUILD PARTITION = '
11
-
+ CASE WHEN EXISTS(SELECT TOP 11FROMsys.partition_schemes s WHEREs.data_space_id=dbindexes.data_space_id) THEN CAST(indexstats.partition_numberASVARCHAR(3)) ELSE 'ALL' END
12
-
+' WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 1 MINUTES, ABORT_AFTER_WAIT = SELF)), '
13
-
+'SORT_IN_TEMPDB = ON);'AS CmdRebuild
12
+
+ CASE WHEN EXISTS(SELECT TOP 11FROMsys.partition_schemes s WHEREs.data_space_id=dbindexes.data_space_id)
13
+
THEN CAST(indexstats.partition_numberASVARCHAR(3)) ELSE 'ALL' END
14
+
+' WITH ('
15
+
+ CASE WHEN ISNULL(dbindexes.[type_desc], '') LIKE'%COLUMNSTORE'
0 commit comments