SQL XP 07
SQL XP 07
Objectives
In this lesson, you will learn to:
Create a clustered index
Create a nonclustered index
Use the Index Tuning Wizard
Understand Index Enhancements
Implementing Indexes
Getting Started
An index is an internal table structure that SQL Server uses
to provide quick access to rows of a table based on the
values of one or more columns
Advantages of Using Indexes
Improve the speed of the execution of queries
Enforce uniqueness of data
Speed up joins between tables
Implementing Indexes
Task List
Identify how to speed up data retrieval
Draft the statement to create an index
Create the index in the database
Verify that the index has been created
Verify that the query execution is faster
Implementing Indexes
Just a Minute…
How many clustered indexes can be created per table?
Which index organizes data logically but does not store data
physically?
Implementing Indexes
Task List
Identify a method to analyze the use of indexes
Perform the analysis
Verify that the analysis has been performed
Implementing Indexes
Index Enhancements
Fill Factor
FILLFACTOR clause improves performance of the system
by minimizing the amount of page splitting that occurs each
time an index page becomes full
Syntax
CREATE CLUSTERED INDEX index_name
ON table_name (column_name)
WITH FILLFACTOR =
percentage_fillfactor
Implementing Indexes
Just a Minute…
Susan wants to minimize the amount of page splitting that
occurs each time an index page is full. What should she use?
Implementing Indexes
Summary
In this lesson, you learned that:
Indexes are created to enhance the performance of queries.
There are two types of indexes – clustered and nonclustered.
Indexes are created using the CREATE INDEX statement.
Data is physically sorted in a clustered index.
Clustered indexes should be built on an attribute whose values
are unique and do not change often.
In a nonclustered index, the physical order of rows is not the
same as that of the index order.
Implementing Indexes
Summary (Contd.)
A nonclustered index should be built on an attribute which is
normally used in joins and the WHERE clause. The values of
this attribute may often change.
A nonclustered index is the default index that is created with
the CREATE INDEX command.
The Index Tuning Wizard can be used to analyze the optimal
use of indexes in the query entered in the Query Analyzer
window.
SQL Server provides the FILLFACTOR clause to improve
performance of the system by minimizing the amount of page
splitting that occurs each time an index page becomes full.
Implementing Indexes
Summary (Contd.)
The DBCC SHOWCONTIG command is mainly used to find
out whether the table or index is heavily fragmented. Table
fragmentation normally occurs when a large number of insert
and update operations are performed on the table.
The DBCC INDEXDEFRAG command is used to defragment
clustered and secondary indexes of the specified table or view.