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
This topic describes how to enable a disabled index in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)]. After an index is disabled, it remains in a disabled state until it is rebuilt or dropped
25
-
26
-
**In This Topic**
27
-
28
-
-**Before you begin:**
29
-
30
-
[Limitations and Restrictions](#Restrictions)
31
-
32
-
[Security](#Security)
33
-
34
-
-**To enable a disabled index, using:**
35
-
36
-
[SQL Server Management Studio](#SSMSProcedure)
37
-
38
-
[Transact-SQL](#TsqlProcedure)
39
-
40
-
## <aname="BeforeYouBegin"></a> Before You Begin
41
-
42
-
### <aname="Restrictions"></a> Limitations and Restrictions
43
-
44
-
- After rebuilding the index, any constraints that were disabled because of disabling the index must be manually enabled. PRIMARY KEY and UNIQUE constraints are enabled by rebuilding the associated index. This index must be rebuilt (enabled) before you can enable FOREIGN KEY constraints that reference the PRIMARY KEY or UNIQUE constraint. FOREIGN KEY constraints are enabled by using the ALTER TABLE CHECK CONSTRAINT statement.
45
-
46
-
- Rebuilding a disabled clustered index cannot be performed when the ONLINE option is set to ON.
47
-
48
-
- When the clustered index is disabled or enabled and the nonclustered index is disabled, the clustered index action has the following results on the disabled nonclustered index.
49
-
50
-
|Clustered Index Action|Disabled Nonclustered Index ...|
|ALTER INDEX ALL REBUILD.|Is rebuilt and enabled.|
54
-
|DROP INDEX.|Remains disabled.|
55
-
|CREATE INDEX WITH DROP_EXISTING.|Remains disabled.|
56
-
57
-
Creating a new clustered index, behaves the same as ALTER INDEX ALL REBUILD.
58
-
59
-
- Allowed actions on nonclustered indexes associated with a clustered index depend on the state, whether disabled or enabled, of both index types. The following table summarizes the allowed actions on nonclustered indexes.
60
-
61
-
|Nonclustered Index Action|When both the clustered and nonclustered indexes are disabled.|When the clustered index is enabled and the nonclustered index is in either state.|
|CREATE INDEX WITH DROP_EXISTING.|The action fails.|The action succeeds.|
66
-
67
-
- When rebuilding disabled compressed nonclustered indexes, data_compression will default to 'none', meaning that indexes will be uncompressed. This is due to compression settings metadata is lost when nonclustered indexes are disabled. To work around this you must specify explicit data compression in rebuild statement.
68
-
69
-
### <aname="Security"></a> Security
70
-
71
-
#### <aname="Permissions"></a> Permissions
72
-
Requires ALTER permission on the table or view. If using DBCC DBREINDEX, user must either own the table; or be a member of the **sysadmin** fixed server role; or the **db_ddladmin** and **db_owner** fixed database roles.
73
-
74
-
## <aname="SSMSProcedure"></a> Using SQL Server Management Studio
75
-
76
-
#### To enable a disabled index
77
-
78
-
1. In Object Explorer, click the plus sign to expand the database that contains the table on which you want to enable an index.
79
-
80
-
2. Click the plus sign to expand the **Tables** folder.
81
-
82
-
3. Click the plus sign to expand the table on which you want to enable an index.
83
-
84
-
4. Click the plus sign to expand the **Indexes** folder.
85
-
86
-
5. Right-click the index you want to enable and select **Rebuild**.
87
-
88
-
6. In the **Rebuild Indexes** dialog box, verify that the correct index is in the **Indexes to rebuild** grid and click **OK**.
89
-
90
-
#### To enable all indexes on a table
91
-
92
-
1. In Object Explorer, click the plus sign to expand the database that contains the table on which you want to enable the indexes.
93
-
94
-
2. Click the plus sign to expand the **Tables** folder.
95
-
96
-
3. Click the plus sign to expand the table on which you want to enable the indexes.
97
-
98
-
4. Right-click the **Indexes** folder and select **Rebuild All**.
99
-
100
-
5. In the **Rebuild Indexes** dialog box, verify that the correct indexes are in the **Indexes to rebuild** grid and click **OK**. To remove an index from the **Indexes to rebuild** grid, select the index and then press the Delete key.
101
-
102
-
The following information is available in the **Rebuild Indexes** dialog box:
103
-
104
-
## <aname="TsqlProcedure"></a> Using Transact-SQL
105
-
106
-
#### To enable a disabled index using ALTER INDEX
107
-
108
-
1. In **Object Explorer**, connect to an instance of [!INCLUDE[ssDE](../../includes/ssde-md.md)].
109
-
110
-
2. On the Standard bar, click **New Query**.
111
-
112
-
3. Copy and paste the following example into the query window and click **Execute**.
113
-
114
-
```
115
-
USE AdventureWorks2022;
116
-
GO
117
-
-- Enables the IX_Employee_OrganizationLevel_OrganizationNode index
118
-
-- on the HumanResources.Employee table.
119
-
120
-
ALTER INDEX IX_Employee_OrganizationLevel_OrganizationNode ON HumanResources.Employee
121
-
REBUILD;
122
-
GO
123
-
```
124
-
125
-
#### To enable a disabled index using CREATE INDEX
126
-
127
-
1. In **Object Explorer**, connect to an instance of [!INCLUDE[ssDE](../../includes/ssde-md.md)].
128
-
129
-
2. On the Standard bar, click **New Query**.
130
-
131
-
3. Copy and paste the following example into the query window and click **Execute**.
132
-
133
-
```
134
-
USE AdventureWorks2022;
135
-
GO
136
-
-- re-creates the IX_Employee_OrganizationLevel_OrganizationNode index
137
-
-- on the HumanResources.Employee table
138
-
-- using the OrganizationLevel and OrganizationNode columns
139
-
-- and then deletes the existing IX_Employee_OrganizationLevel_OrganizationNode index
140
-
CREATE INDEX IX_Employee_OrganizationLevel_OrganizationNode ON HumanResources.Employee
141
-
(OrganizationLevel, OrganizationNode)
142
-
WITH (DROP_EXISTING = ON);
143
-
GO
144
-
```
145
-
146
-
#### To enable a disabled index using DBCC DBREINDEX
147
-
148
-
1. In **Object Explorer**, connect to an instance of [!INCLUDE[ssDE](../../includes/ssde-md.md)].
149
-
150
-
2. On the Standard bar, click **New Query**.
151
-
152
-
3. Copy and paste the following example into the query window and click **Execute**.
153
-
154
-
```
155
-
USE AdventureWorks2022;
156
-
GO
157
-
-- enables the IX_Employee_OrganizationLevel_OrganizationNode index
#### To enable all indexes on a table using ALTER INDEX
164
-
165
-
1. In **Object Explorer**, connect to an instance of [!INCLUDE[ssDE](../../includes/ssde-md.md)].
166
-
167
-
2. On the Standard bar, click **New Query**.
168
-
169
-
3. Copy and paste the following example into the query window and click **Execute**.
170
-
171
-
```
172
-
USE AdventureWorks2022;
173
-
GO
174
-
-- enables all indexes
175
-
-- on the HumanResources.Employee table
176
-
ALTER INDEX ALL ON HumanResources.Employee
177
-
REBUILD;
178
-
GO
179
-
```
180
-
181
-
#### To enable all indexes on a table using DBCC DBREINDEX
182
-
183
-
1. In **Object Explorer**, connect to an instance of [!INCLUDE[ssDE](../../includes/ssde-md.md)].
184
-
185
-
2. On the Standard bar, click **New Query**.
186
-
187
-
3. Copy and paste the following example into the query window and click **Execute**.
188
-
189
-
```
190
-
USE AdventureWorks2022;
191
-
GO
192
-
-- enables all indexes
193
-
-- on the HumanResources.Employee table
194
-
DBCC DBREINDEX ("HumanResources.Employee", " ");
195
-
GO
196
-
```
197
-
198
-
For more information, see [ALTER INDEX (Transact-SQL)](../../t-sql/statements/alter-index-transact-sql.md), [CREATE INDEX (Transact-SQL)](../../t-sql/statements/create-index-transact-sql.md), and [DBCC DBREINDEX (Transact-SQL)](../../t-sql/database-console-commands/dbcc-dbreindex-transact-sql.md).
199
-
200
-
26
+
This article describes how to enable a disabled index in [!INCLUDE [ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE [tsql](../../includes/tsql-md.md)]. After an index is disabled, it remains in a disabled state until it rebuilds or is dropped.
27
+
28
+
## Limitations
29
+
30
+
After the index rebuilds, any constraints that were disabled because of disabling the index must be manually enabled. `PRIMARY KEY` and `UNIQUE` constraints are enabled by rebuilding the associated index. This index must be rebuilt (enabled) before you can enable `FOREIGN KEY` constraints that reference the `PRIMARY KEY` or `UNIQUE` constraint. `FOREIGN KEY` constraints are enabled by using the `ALTER TABLE CHECK CONSTRAINT` statement.
31
+
32
+
Rebuilding a disabled clustered index can't be performed when the `ONLINE` option is set to `ON`.
33
+
34
+
When the clustered index is disabled or enabled and the nonclustered index is disabled, the clustered index action has the following results on the disabled nonclustered index.
35
+
36
+
| Clustered index action | Disabled nonclustered index status |
37
+
| --- | --- |
38
+
|`ALTER INDEX REBUILD`| Remains disabled |
39
+
|`ALTER INDEX ALL REBUILD`| Rebuilt and enabled |
40
+
|`DROP INDEX`| Rebuilt and enabled |
41
+
|`CREATE INDEX WITH DROP_EXISTING`| Remains disabled |
42
+
43
+
Creating a new clustered index behaves the same as `ALTER INDEX ALL REBUILD`.
44
+
45
+
Allowed actions on nonclustered indexes associated with a clustered index depend on the state, whether disabled or enabled, of both index types. The following table summarizes the allowed actions on nonclustered indexes.
46
+
47
+
| Nonclustered index action | When both the clustered and nonclustered indexes are disabled | When the clustered index is enabled and the nonclustered index is in either state |
48
+
| --- | --- | --- |
49
+
|`ALTER INDEX REBUILD`| The action fails | The action succeeds |
50
+
|`DROP INDEX`| The action succeeds | The action succeeds |
51
+
|`CREATE INDEX WITH DROP_EXISTING`| The action fails | The action succeeds |
52
+
53
+
When rebuilding disabled compressed nonclustered indexes, `data_compression` defaults to `none`, meaning that indexes are uncompressed. This is due to compression settings metadata is lost when nonclustered indexes are disabled. To work around this issue, you must specify explicit data compression in rebuild statement.
54
+
55
+
## Permissions
56
+
57
+
Requires `ALTER` permission on the table or view. If using `DBCC DBREINDEX`, you must either own the table or be a member of the **sysadmin** fixed server role, or a member of the **db_ddladmin** or **db_owner** fixed database roles.
58
+
59
+
## Use SQL Server Management Studio
60
+
61
+
### Enable a disabled index
62
+
63
+
1. In Object Explorer, select the plus sign to expand the database that contains the table on which you want to enable an index.
64
+
65
+
1. Select the plus sign to expand the **Tables** folder.
66
+
67
+
1. Select the plus sign to expand the table on which you want to enable an index.
68
+
69
+
1. Select the plus sign to expand the **Indexes** folder.
70
+
71
+
1. Right-click the index you want to enable and select **Rebuild**.
72
+
73
+
1. In the **Rebuild Indexes** dialog box, verify that the correct index is in the **Indexes to rebuild** grid and select **OK**.
74
+
75
+
### Enable all indexes on a table
76
+
77
+
1. In Object Explorer, select the plus sign to expand the database that contains the table on which you want to enable the indexes.
78
+
79
+
1. Select the plus sign to expand the **Tables** folder.
80
+
81
+
1. Select the plus sign to expand the table on which you want to enable the indexes.
82
+
83
+
1. Right-click the **Indexes** folder and select **Rebuild All**.
84
+
85
+
1. In the **Rebuild Indexes** dialog box, verify that the correct indexes are in the **Indexes to rebuild** grid and select **OK**. To remove an index from the **Indexes to rebuild** grid, select the index and then press the Delete key.
86
+
87
+
The following information is available in the **Rebuild Indexes** dialog box:
Execute the following Transact-SQL script. This example enables the `IX_Employee_OrganizationLevel_OrganizationNode` index on the `HumanResources.Employee` table.
Execute the following Transact-SQL script. This example recreates the `IX_Employee_OrganizationLevel_OrganizationNode` index on the `HumanResources.Employee` table, using the `OrganizationLevel` and `OrganizationNode` columns, and then deletes the existing `IX_Employee_OrganizationLevel_OrganizationNode` index.
Execute the following Transact-SQL script. This example enables the `IX_Employee_OrganizationLevel_OrganizationNode` index on the `HumanResources.Employee` table.
0 commit comments