Index Object (SQL-DMO)
The Index object exposes the attributes of a single Microsoft® SQL Server™ index.
Remarks
A SQL Server index optimizes access to data in SQL Server tables. Indexes are also used to enforce some constraints, such as UNIQUE and PRIMARY KEY constraints.
With the Index object, you can:
- Create a SQL Server index.
- Create SQL Server data distribution statistics.
- Remove a SQL Server index.
- Remove SQL Server data distribution statistics.
- Rebuild a SQL Server index.
- Update data distribution statistics.
The Name property of an Index object uses the SQL Server data type sysname. Within a SQL Server database, all index names must be unique.
To create a SQL Server index
- Create an Index object.
- Set the Name property.
- Set the IndexedColumns property to the column or columns participating in the index.
- Set the Type property of the Index object to control the attributes of the index created (optional). If not set, a nonclustered index allowing duplicate values is created. For more information about SQL Server index types and limitations on indexes applied to tables, see CREATE INDEX.
- Set optional properties, such as FileGroup.
- Get the Table object that references the SQL Server table you want from the Tables collection of a connected Database object.
- Use the BeginAlter method of the Table object to mark the start of changes to the SQL Server table.
- Add the Index object to the Indexes collection of the selected Table object.
- Use the DoAlter method of the Table object to mark the end of changes and create the index on the SQL Server.
To remove an existing SQL Server index
- Get the Table object that references the SQL Server table you want from the Tables collection of a connected Database object.
- Use the BeginAlter method of the Table object to mark the start of changes to the SQL Server table.
- Get the Index object representing the SQL Server index to remove from the Indexes collection of the selected Table object.
- Use the Remove method of the Index object to remove the Index object from the Indexes collection of the Table object.
- Use the DoAlter method of the Table object to mark the end of changes and remove the SQL Server index from the SQL Server table.
Methods
Properties
(c) 1988-98 Microsoft Corporation. All Rights Reserved.