----Diable Index
----(1) Disabling Index Using T-SQL
USE AdventureWorks
GO
ALTER INDEX [IX_Address_StateProvinceID] ON Person.Address DISABLE
GO
----(2) Disabling Index Using SQL Server Management Studio (SSMS)
----Enable Index
----(1) Enable Index Using ALTER INDEX REBUILD Statement
ALTER INDEX [IX_Address_StateProvinceID] ON Person.Address REBUILD
GO
----(2) Enable Index Using CREATE INDEX WITH DROP_EXISTING Statement
USE AdventureWorks
GO
CREATE NONCLUSTERED INDEX [IX_Address_StateProvinceID] ON [Person].[Address]
(
[StateProvinceID] ASC
)WITH (DROP_EXISTING = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
----(3) Enable Index Using SQL Server Management Studio (SSMS)
Drop Index
You cannot drop an index used by either a PRIMARY KEY or UNIQUE constraint, except by dropping the constraint. By modifying the index, for example, to modify the fill factor value used by the index, you can essentially drop and re-create an index used by a PRIMARY KEY or UNIQUE constraint without having to drop and re-create the constraint.
DROP INDEX
{ <drop_relational_or_xml_or_spatial_index> [ ,...n ]
| <drop_backward_compatible_index> [ ,...n ]
}
When a nonclustered index is dropped, the index definition is removed from metadata and the index data pages (the B-tree) are removed from the database files.
When a clustered index is dropped, the index definition is removed from metadata and the data rows that were stored in the leaf level of the clustered index are stored in the resulting unordered table, a heap.
All the space previously occupied by the index is regained. This space can then be used for any database object.
An index cannot be dropped if the filegroup in which it is located is offline or set to read-only.
When the clustered index of an indexed view is dropped, all nonclustered indexes and auto-created statistics on the same view are automatically dropped. Manually created statistics are not dropped.
The syntaxtableorviewname.indexname is maintained for backward compatibility. An XML index or spatial index cannot be dropped by using the backward compatible syntax.
When indexes with 128 extents or more are dropped, the Database Engine defers the actual page deallocations, and their associated locks, until after the transaction commits. For more information, see Dropping and Rebuilding Large Objects.
Sometimes indexes are dropped and re-created to reorganize or rebuild the index, such as to apply a new fill factor value or to reorganize data after a bulk load. To do this, using ALTER INDEXis more efficient, especially for clustered indexes. ALTER INDEX REBUILD has optimizations to prevent the overhead of rebuilding the nonclustered indexes.
When you drop all indexes on a table, drop the nonclustered indexes first and the clustered index last. That way, no indexes have to be rebuilt.
Using the MOVE TO Clause
If MOVE TO is not specified, the resulting table will be located in the same partition scheme or filegroup as was defined for the clustered index.
Dropping Clustered Indexes Online
You can specify the ONLINE option when you drop a clustered index. When set to ON, queries and modifications to the underlying data and associated nonclustered indexes are not blocked by the DROP INDEX transaction
You can drop the clustered index and move the resulting unordered table (heap) to another filegroup or partition scheme in a single transaction by specifying the MOVE TO option.
The MOVE TO option has the following restrictions:
- It is not valid for indexed views or nonclustered indexes.
- The specified partition scheme or filegroup must already exist.
Setting the MAXDOP Index Option
You can override the max degree of parallelism configuration option of sp_configure for the drop index operation by specifying the MAXDOP index option.
Full-Text Indexes
An index specified as the full-text key for the table cannot be dropped. View index properties to determine whether the index is a full-text key.
Disk Space Requirements for Index DDL Operations
when you create, rebuild, or drop indexes. Inadequate disk space can degrade performance or even cause the index operation to fail
Index Operations That Require No Additional Disk Space
The following index operations require no additional disk space:
ALTER INDEX REORGANIZE; however, log space is required.
DROP INDEX when you are dropping a nonclustered index.
DROP INDEX when you are dropping a clustered index offline without specifying the MOVE TO clause and nonclustered indexes do not exist.
CREATE TABLE (PRIMARY KEY or UNIQUE constraints)
Index Operations That Require Additional Disk Space
All other index DDL operations require additional temporary disk space to use during the operation, and permanent disk space to store the new index structure or structures.
When a new index structure is created, disk space for both the old (source) and new (target) structures is required in their appropriate files and filegroups. The old structure is not deallocated until the index creation transaction commits.
The following index DDL operations create new index structures and require additional disk space:
CREATE INDEX
CREATE INDEX WITH DROP_EXISTING
ALTER INDEX REBUILD
ALTER TABLE ADD CONSTRAINT (PRIMARY KEY or UNIQUE)
ALTER TABLE DROP CONSTRAINT (PRIMARY KEY or UNIQUE) when the constraint is based on a clustered index
DROP INDEX MOVE TO (Applies only to clustered indexes.)
Temporary Disk Space for Sorting
If sorting is required, sorting occurs one new index at a time. For example, when you rebuild a clustered index and associated nonclustered indexes within a single statement, the indexes are sorted one after the other. Therefore, the additional temporary disk space that is required for sorting only has to be as large as the largest index in the operation. This is almost always the clustered index.
If the SORTINTEMPDB option is set to ON, the largest index must fit into tempdb. Although this option increases the amount of temporary disk space that is used to create an index, it may reduce the time that is required to create an index when tempdb is on a set of disks different from the user database. For more information about sorting in tempdb, see tempdb and Index Creation.
If SORTINTEMPDB is set to OFF (the default) each index, including partitioned indexes, is sorted in its destination disk space; and only the disk space for the new index structures is required.
Temporary Disk Space for Online Index Operations
If a clustered index is created, rebuilt, or dropped online, a temporary nonclustered index is created to map old bookmarks to new bookmarks. If the SORTINTEMPDB option is set to ON, this temporary index is created in tempdb. If SORTINTEMPDB is set to OFF, the same filegroup or partition scheme as the target index is used. The temporary mapping index contains one record for each row in the table, and its contents is the union of the old and new bookmark columns, including uniqueifiers and record identifiers and including only a single copy of any column used in both bookmarks.
http://msdn.microsoft.com/en-us/library/ms179542.aspx
http://www.mssqltips.com/tipprint.asp?tip=1788
http://msdn.microsoft.com/en-us/library/ms190691.aspx