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
@tableName nvarchar(261) = NULL --Table which indexes should be scripted
41
-
,@newTableName nvarchar(261) = NULL --New table Name. If NULL then Indexes are scripted for original table
42
-
,@partitionID int = 0 --Specifies how the ON [FileGroup] is being scripted
43
-
,@scriptPrimaryKey bit = 1 --Specifies whether Primary key should be scripted
44
-
,@scriptUniqueConstraints bit = 1 --Specifies whether Unique Constraints should be scripted
45
-
,@scriptIndexes bit = 1 --Specifies wheteher Indexes should be scripted
46
-
,@scriptDisabledIndexes bit = 0 --Specifies whether to script disabled indexes
47
-
,@scriptAlterIndexDisable bit = 1 --For Disabled indexes scripts the ALTER INDEX DISABLE
47
+
@tableName nvarchar(261) = NULL --Table which indexes should be scripted
48
+
,@newTableName nvarchar(261) = NULL --New table Name. If NULL then Indexes are scripted for original table
49
+
,@partitionID int = 0 --Specifies how the ON [FileGroup] is being scripted
50
+
,@scriptPrimaryKey bit = 1 --Specifies whether Primary key should be scripted
51
+
,@scriptUniqueConstraints bit = 1 --Specifies whether Unique Constraints should be scripted
52
+
,@scriptIndexes bit = 1 --Specifies wheteher Indexes should be scripted
53
+
,@scriptDisabledIndexes bit = 0 --Specifies whether to script disabled indexes
54
+
,@scriptAlterIndexDisable bit = 1 --For Disabled indexes scripts the ALTER INDEX DISABLE
48
55
,@scriptDropExisting bit = 1 --Scripts DROP_EXISTING = ON or DROP_EXISTING = OFF
49
-
,@scriptIndexTypes nvarchar(100) = N'1,2,3,5,6' --Bitmask of Index types to Script Currently 1,2,5,6
56
+
,@scriptIndexTypes nvarchar(100) = N'1,2,3,5,6' --Bitmask of Index types to Script Currently 1,2,5,6
50
57
,@indexNames nvarchar(max) = '%' --Comma Separated List of Index Names to Script. Supports LIKE wildcards
51
58
,@noInfoMsg bit = 0 --Disbles printing of header and informational messages
52
59
,@outputScript nvarchar(max) = NULL OUTPUT --Outputs script to the @outputScript parameters. Allows utilization of the script in other stored procedures
@@ -58,26 +65,26 @@ Parameters:
58
65
59
66
60
67
Index types and corresponding bit positions
61
-
1 = Clustered
62
-
2 = Nonclustered
63
-
3 = XML
64
-
4 = Spatial
65
-
5 = Clustered columnstore index - Applies to: SQL Server 2014 and above
66
-
6 = Nonclustered columnstore index - Applies to: SQL Server 2012 and above
67
-
7 = Nonclustered hash index - Applies to: SQL Server 2014 and above
68
+
1 = Clustered
69
+
2 = Nonclustered
70
+
3 = XML
71
+
4 = Spatial
72
+
5 = Clustered columnstore index - Applies to: SQL Server 2014 and above
73
+
6 = Nonclustered columnstore index - Applies to: SQL Server 2012 and above
74
+
7 = Nonclustered hash index - Applies to: SQL Server 2014 and above
THENNCHAR(13) +NCHAR(10) +N'ALTER INDEX '+QUOTENAME(ISNULL(@newTbName +'_', '') +i.name) +N' ON '+ @newTable +N' DISABLE'
389
+
THENNCHAR(13) +NCHAR(10) +N'ALTER INDEX '+QUOTENAME(ISNULL(@newTbName +'_', '') +i.name) +N' ON '+ @newTable +N' DISABLE'
383
390
ELSEN''
384
391
ENDAS IndexScript
385
392
FROMsys.indexes i
386
393
INNER JOIN #indexNames ixn ONi.name=ixn.IndexName
387
394
LEFT JOINsys.xml_indexes xi ONxi.object_id=i.object_idandxi.index_id=i.index_id
388
-
LEFT JOINsys.stats s ONs.object_id=i.object_idANDs.stats_id=i.index_id--Statistics to get the NO RECOMPUTE information
389
-
INNER JOINsys.data_spaces ds ONi.data_space_id=ds.data_space_idANDds.type<>'FX'--dsta_spaces to find out the FileGroup/partition scheme informaiton (exclude MEMORY OPTIMIZED data Spaces
390
-
LEFT JOINsys.partition_schemes ps ONi.data_space_id=ps.data_space_id--details of partition scheme
395
+
LEFT JOINsys.stats s ONs.object_id=i.object_idANDs.stats_id=i.index_id--Statistics to get the NO RECOMPUTE information
396
+
INNER JOINsys.data_spaces ds ONi.data_space_id=ds.data_space_idANDds.type<>'FX'--dsta_spaces to find out the FileGroup/partition scheme informaiton (exclude MEMORY OPTIMIZED data Spaces
397
+
LEFT JOINsys.partition_schemes ps ONi.data_space_id=ps.data_space_id--details of partition scheme
391
398
LEFT JOINsys.destination_data_spaces dds ONdds.partition_scheme_id=i.data_space_idAND ds.[type] =N'PS'ANDdds.destination_id= @partitionID --Partitions and destinations
392
-
LEFT JOINsys.filegroups dfg ONdfg.data_space_id=dds.data_space_id--Destination file groups for partitioned index
399
+
LEFT JOINsys.filegroups dfg ONdfg.data_space_id=dds.data_space_id--Destination file groups for partitioned index
393
400
LEFT JOINsys.partitions p ONp.object_id=i.object_idANDp.index_id=i.index_idAND (p.partition_number= @partitionID OR (ds.[type] =N'FG'ANDp.partition_number=1)) --To determine compression
394
401
WHERE
395
402
i.object_id=OBJECT_ID(@tableName)
@@ -400,11 +407,11 @@ RAISERROR(N' ,@noXml bit = 0
400
407
AND
401
408
i.typeIN (SELECT IndexType FROM @indexes) --Script only supported indexes
0 commit comments