Views, indexes, and query performance
Clustered and nonclustered indexes
Compare index types in the frozen product table.
Lesson 73 of 84
Reading: about 2 min
Lesson + practice: about 15 min
Difficulty: Advanced
On this page4 sections
This lesson uses DDI_SQL_Training dataset v1.0.0 on SQL Server 2019 or later. Compare index types in the frozen product table.
Run the example
sql
SELECT name AS IndexName, type_desc AS IndexType, is_unique AS IsUnique
FROM sys.indexes
WHERE object_id = OBJECT_ID(N'dbo.Products') AND index_id > 0
ORDER BY index_id;Read it step by step
- The clustered index organizes data rows by key at its leaf level.
- A nonclustered index has its own key structure and points to rows through a locator.
- is_unique describes enforced key uniqueness, not whether the optimizer will use the index.
Check the result
| IndexName | IndexType | IsUnique |
|---|---|---|
| PK_Products | CLUSTERED | 1 |
| UQ_Products_Name | NONCLUSTERED | 1 |
A table can have one clustered index and multiple nonclustered indexes.
Practice
Inspect index type and uniqueness on dbo.Orders.
Check your answer and expected result
Reveal answer
sql
SELECT name AS IndexName, type_desc AS IndexType, is_unique AS IsUnique
FROM sys.indexes
WHERE object_id = OBJECT_ID(N'dbo.Orders') AND index_id > 0
ORDER BY index_id;| IndexName | IndexType | IsUnique |
|---|---|---|
| PK_Orders | CLUSTERED | 1 |
The result distinguishes clustered and nonclustered definitions on Orders.
Your progress
Reveal the check answer or reach the end to complete this lesson.