Designing an Index

When Microsoft® SQL Server™ executes a query, the query optimizer evaluates the costs of the available methods for retrieving the data and uses the most efficient method. It can perform a table scan, or it can use an index if one exists. When it performs a table scan, SQL Server starts at the beginning of the table, steps row-by-row through all the rows in the table, and extracts the rows that meet the criteria of the query. When SQL Server uses an index, it finds the storage location of the rows needed by the query and extracts only the needed rows.

When you are considering whether to create an index on a column, consider if and how an indexed column is to be used in queries. Indexes assist when a query:

Queries using LIKE comparisons can benefit from an index if the pattern starts with a specific character string, for example 'abc%', but not if the pattern starts with a wildcard search, for example '%xyz'.

In many queries, the benefits of indexes can be combined. For example, an index enables a range query in addition to covering the query. SQL Server can use multiple indexes for a single table in the same query, as well as combining multiple indexes (using a join algorithm) so that the search keys together cover a query. Additionally, SQL Server automatically determines which indexes to exploit for a query and ensures that all indexes for a table are maintained when the table is modified.

Additional Guidelines for Designing Indexes

Additional guidelines to consider when designing indexes include:

Index Characteristics

After you have determined that an index is justified for a column, you can customize the type of index that best fits your situation. Characteristics of indexes include:

You can also customize the initial storage characteristics of the index to optimize its maintenance by setting a fill factor, and customize its location using files and filegroups to optimize performance.

See Also
Designing Tables Query Tuning
Fill Factor Understanding Merge Joins
Placing Indexes on Filegroups Understanding Nested Loops Joins

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.