Non-Clustered Index — Complete Guide
Non-Clustered Index — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of SQL Server Tutorial on Toolliyo Academy.
On this page
SQL Server Tutorial · Lesson 32 of 100
Non-Clustered Index
SQL basics ✓ → Queries → Advanced
Queries · 2 — JOINs · ~6 min · SQL — Indexing & Performance
What is this?
A non-clustered index is a separate B-tree pointing to heap RIDs or clustered keys. Many NC indexes are allowed. They speed seeks on non-clustering columns.
Why should you care?
You cluster on InvoiceId but search by CustomerId — an NC index on CustomerId avoids scanning the whole table.
See it live — copy this example
Run in SQL Server Management Studio (SSMS) or Azure Data Studio.
USE DataVerse;
CREATE NONCLUSTERED INDEX IX_Orders_CustomerId
ON dbo.Orders (CustomerId)
INCLUDE (Amount, City);
SELECT OrderId, Amount, City
FROM dbo.Orders WITH (INDEX (IX_Orders_CustomerId))
WHERE CustomerId = 1;
What happened?
- Index key is CustomerId; INCLUDE stores Amount and City at the leaf so the query can avoid key lookups for those columns.
- The INDEX hint forces use for demo — remove hints in production after verifying plans.
Practice next
- Create IX_Orders_CustomerId.
- Run the SELECT with actual plan — look for Index Seek.
- Drop the hint and confirm the optimizer still picks it.
- Remove INCLUDE and see Key Lookup in the plan.
- Query sys.dm_db_index_usage_stats for seeks vs updates.
Remember
NC indexes support alternate search paths. INCLUDE covers extra selected columns. Balance read speed vs write cost.
Customer order history
Account page lists DataVerse orders by CustomerId.
Outcome: NC index keeps history snappy as orders grow.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!