SQL Server
Indexing Basics
August 11, 2015
Mindy Curnutt
Director of DB Architecture
TMW Systems, Inc.
@sqlgirl
Clustered Indexes
Nonclustered Indexes
1
2
1
Clustered Indexes
• What are they?
• Desired Qualities
2
Clustered Indexes
What are they?
• Sort Order of the data within the table
• One per table
3
Clustered Indexes
Desired Qualities
• Increasing
• Static
• Narrow Data Type
• Unique
4
Clustered Indexes
Increasing
• Data is added to the end of the index
• Reduces fragmentation
5
Clustered Indexes
Static
• Changes cause…
• Fragmentation
• Additional overhead for
Non Clustered Indexes
6
Clustered Indexes
Narrow Data Type
• Less Data Duplicated
• Smaller…
• Databases
• Backups
• Maintenance Plan Times
• Scans
7
Clustered Indexes
Unique
• Not Required
• Prevents Uniqueifier
• Best to be narrow!
8
Clustered Indexes
Demos
• No Clustered Index (Heap)
• Non Unique Clustered Index
• Unique Clustered Index
9
Non Clustered Indexes
• What are they?
• Why are they useful?
• When are they not useful?
10
Non Clustered Indexes
What are they?
11
Clustered Index Non Clustered Index
Non Clustered Indexes
Why are they useful?
• Smaller than table itself
• Seek vs Scan
12
SELECT COUNT(*) FROM addressbook
WHERE phone LIKE '707942%'
Non Clustered Indexes
When are they not useful?
• When too many rows are returned and all the columns
needed for the query are not present in the nonclustered
index
• Extra work for SQL regarding inserts, updates and
deletes
13
Non Clustered Indexes
When are they not useful?
14
SELECT COUNT(*) FROM addressbook
WHERE phone LIKE '707942%' AND
[street name] LIKE 'Stringer%'

Geek Sync | SQL Server Indexing Basics