Lesson 32/100

Tutorials SQL Server Tutorial

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 ✓QueriesAdvanced

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

  1. Create IX_Orders_CustomerId.
  2. Run the SELECT with actual plan — look for Index Seek.
  3. Drop the hint and confirm the optimizer still picks it.
  4. Remove INCLUDE and see Key Lookup in the plan.
  5. 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.

Mid PDF Detailed
Slower Queries: Fragmented indexes cause the database engine to read more data?
Short answer: pages, slowing down query performance. Real-world example (ShopNest) ShopNest adds an index on Orders(CustomerId, CreatedAt) because “my recent orders” is queried constantly. Say this in the interview Defin…
Mid PDF Detailed
Indexing:?
Short answer: Create indexes on columns that are used in WHERE clauses, JOIN conditions, and ORDER BY clauses. Use covering indexes to avoid full table scans and improve performance. Real-world example (ShopNest) ShopNes…
Mid PDF Detailed
Faster Search: Indexes allow the database to locate rows much faster than a full?
Short answer: Faster Search: Indexes allow the database to locate rows much faster than a full? is a common interview topic in SQL & Databases. Give a clear definition, then one concrete example. Real-world example (…
Mid PDF Detailed
Large Tables: Indexes are especially helpful for large tables that are queried?
Short answer: Large Tables: Indexes are especially helpful for large tables that are queried? is a common interview topic in SQL & Databases. Give a clear definition, then one concrete example. Real-world example (Sh…
Mid PDF Detailed
Larger Indexes: Fragmentation can lead to larger index sizes and more disk space?
Short answer: Larger Indexes: Fragmentation can lead to larger index sizes and more disk space? is a common interview topic in SQL & Databases. Give a clear definition, then one concrete example. Real-world example (…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

SQL Server Tutorial
Course syllabus

SQL Server Tutorial

SQL — Foundations
SQL — SQL Queries & Clauses
SQL — Joins & Relationships
SQL — Indexing & Performance
SQL — Stored Procedures & Functions
SQL — Transactions & Concurrency
SQL — Advanced SQL Server
SQL — Security & High Availability
SQL — 2022 & Cloud
SQL — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details