Skip to main content

Clustered vs NonClustered Index

Editorial

Introduction

Now that you understand both clustered and nonclustered indexes individually, it is time to put them side by side. Knowing the differences between these two index types is essential for making good database design decisions.

In this tutorial, you will learn:

  • A direct comparison of clustered vs nonclustered indexes
  • How each type stores data internally
  • Performance differences for common operations
  • How they work together on the same table
  • Decision guidelines for choosing between them

Side-by-Side Comparison

Here is the complete comparison between clustered and nonclustered indexes:

FeatureClustered IndexNonClustered Index
Number per tableExactly 1Up to 999
Physical data orderDefines the physical sort orderDoes not affect physical order
Leaf level containsThe actual data rowsIndex key + row locator (pointer)
Separate structureNo — the index IS the tableYes — a separate B-tree
SizeSame as table dataSmaller (subset of columns)
Key Lookup neededNeverYes, when query needs extra columns
Default creationWith PRIMARY KEYWith UNIQUE constraint
Range queriesExcellent (sequential reads)Good (but may need lookups)
Point lookupsFastFast (plus optional lookup)
INSERT impactRow must go in sorted positionEntry added to separate structure
UPDATE on keyRow may need to physically moveIndex entry updated in place

Visual Comparison: Data Storage

The most important difference is WHERE the data lives:

Side-by-side comparison of clustered and nonclustered indexes showing data storage differences and when to use each

Performance Comparison by Query Type

Different query patterns perform differently depending on the index type:

1. Point Lookup (Single Row)

SELECT * FROM orders WHERE order_id = 42;
Index TypeStepsPerformance
Clustered (on order_id)Seek B-tree → leaf has the dataVery fast
NonClustered (on order_id)Seek B-tree → get pointer → lookup full rowFast (one extra step)

2. Range Query

SELECT * FROM orders WHERE order_date BETWEEN '2017-01-01' AND '2017-06-30';
Index TypeStepsPerformance
Clustered (on order_date)Seek to start → read consecutive pagesExcellent
NonClustered (on order_date)Seek to start → lookup EACH row back to tableSlower (many random I/Os)

3. Covering Query (All Needed Columns in Index)

SELECT customer_id, order_status FROM orders WHERE customer_id = 'ABC';
Index TypeStepsPerformance
NC Index on (customer_id) INCLUDE (order_status)Seek B-tree → leaf has all needed columnsVery fast (no lookup!)

4. Full Table Scan

SELECT * FROM orders;
Index TypeBehavior
ClusteredReads the table in sorted order (sequential I/O)
NonClusteredNot used — SQL Server reads the table directly

How They Work Together

In practice, a well-designed table has one clustered index and several nonclustered indexes that work together:

Generated visual representation from text diagram for How They Work Together.

Important Implication: Clustered Key Width

Since every nonclustered index stores the clustered key in its leaf pages, a wide clustered key (like a GUID) makes ALL nonclustered indexes larger:

Clustered Key TypeSizeImpact on NC Indexes
INT4 bytesMinimal — NC indexes stay small
BIGINT8 bytesSmall — acceptable
UNIQUEIDENTIFIER (GUID)16 bytesSignificant — NC indexes grow
NVARCHAR(100)Up to 200 bytesLarge — NC indexes become bloated

Decision Guide: When to Use Which

Choose Clustered Index For:

ScenarioWhy
Primary key lookupsDirect access to data, no extra step
Range queries (date ranges, price ranges)Sequential reading of sorted data
Columns frequently used in ORDER BYData comes pre-sorted
The most commonly queried columnMaximizes benefit of physical sorting

Choose NonClustered Index For:

ScenarioWhy
Secondary lookup columnsProvides alternative access paths
Foreign key columnsSpeeds up JOIN operations
Columns in WHERE clausesEnables index seeks instead of scans
Multiple search patternsCan create many NC indexes for different queries

Decision Flowchart

Generated visual representation from text diagram for Decision Guide: When to Use Which.

Summary

Here are the key takeaways from comparing clustered and nonclustered indexes:

AspectClusteredNonClustered
Data storageLeaf = actual rowsLeaf = pointers to rows
Per table1Up to 999
Best forRange queries, primary lookupsSecondary lookups, JOINs
Key lookupNever neededMay be needed
Physical orderDefines itIndependent
Key width impactAffects ALL NC indexesAffects only this index

Golden Rules

  1. Every table should have a clustered index (avoid heaps)
  2. Choose the clustered key carefully — it affects everything
  3. Keep the clustered key narrow (INT or BIGINT preferred)
  4. Use nonclustered indexes for secondary access patterns
  5. Use INCLUDE columns to create covering indexes and avoid key lookups

In the next tutorial, you will learn the exact SQL syntax for creating indexes.