Quick revision
The short answer
A clustered index is the table itself: its leaf pages hold the full rows, stored in the order of the clustering key, so a table can have only one. A nonclustered index is a separate structure whose leaf entries hold the index key plus a row locator, which is the clustering key for a clustered table or a RID (a physical row id) for a heap. Because every nonclustered index carries the clustering key, a wide key makes them all larger, so a good clustering key is narrow, unique, static and ever-increasing, such as a BIGINT IDENTITY; a PRIMARY KEY becomes the clustered index by default unless we say NONCLUSTERED.
What to remember
In this answer, we saw that a clustered index is the table itself, with full rows in its leaf pages ordered by the clustering key, so there is only one per table. A nonclustered index stores its key plus a row locator, the clustering key or a RID on a heap, and uses key lookups to fetch other columns unless INCLUDE covers them. Because the clustering key is copied into every nonclustered index, it should be narrow, unique, static and ever-increasing, like a BIGINT IDENTITY, and a PRIMARY KEY becomes clustered by default unless declared NONCLUSTERED.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A clustered index is the table itself: its leaf pages hold the full rows, stored in the order of the clustering key, so a table can have only one. A nonclustered index is a separate structure whose leaf entries hold the index key plus a row locator, which is the clustering key for a clustered table or a RID (a physical row id) for a heap. Because every nonclustered index carries the clustering key, a wide key makes them all larger, so a good clustering key is narrow, unique, static and ever-increasing, such as a BIGINT IDENTITY; a PRIMARY KEY becomes the clustered index by default unless we say NONCLUSTERED.
Why this question is asked
In SQL Server, the choice of clustered index is one of the most important physical design decisions for a table, and it is often made by accident, because declaring a primary key silently creates it. Java developers meet the consequences as slow inserts, large indexes or expensive lookups. Interviewers ask this to check that we understand how rows are actually stored and found. In this answer, we will recap B-tree indexes, see what makes a clustered index different, look at how nonclustered indexes find rows, and explain what makes a good clustering key.
1A Quick Recap of B-Tree Indexes
SQL Server stores indexes as B-trees: a root page at the top, intermediate pages in the middle, and leaf pages at the bottom, all sorted by the index key. To find a key, SQL Server starts at the root and follows pointers down, which takes only three or four page reads even for millions of rows. The question for any index is what the leaf pages contain.
2The Clustered Index Is the Table
In a clustered index, the leaf pages are the data pages: they contain the complete rows, sorted by the clustering key. There is no separate table behind it. That is why a table can have only one clustered index; the rows can only be stored in one order. A table without a clustered index is called a heap, and its rows are stored in no particular order.
Notice that we wrote only PRIMARY KEY. SQL Server made it clustered because the table did not have a clustered index yet. That default is often fine, but it should be a decision, not an accident. A range query on the clustering key, such as WHERE id BETWEEN 1000 AND 2000, is very efficient, because the rows are stored next to each other in that order.
3How a Nonclustered Index Finds the Row
A nonclustered index is a separate B-tree. Its leaf entries hold the index key and a row locator, the information needed to find the full row. In a clustered table, the locator is the clustering key. In a heap, it is a RID, a physical address made of file, page and slot.
| Index | Leaf entry | Finding the full row |
|---|---|---|
| Clustered on id | The whole row, ordered by id | Already there |
| Nonclustered on customer_id | customer_id + id (clustering key) | Key lookup by id in the clustered index |
| Nonclustered on a heap | customer_id + RID (file:page:slot) | RID lookup, direct page read |
| Nonclustered with INCLUDE (total) | customer_id + id + total | Not needed for queries using only these |
So finding rows through a nonclustered index is two steps when the index does not hold every needed column: a seek in the nonclustered index, then a key lookup in the clustered index for each match. For a handful of rows that is cheap; for thousands it can be slower than scanning, which is why the optimizer sometimes ignores an index. INCLUDE adds columns to the leaf level so the index covers the query.
4Why a Wide Clustering Key Hurts Every Index
Because every nonclustered index entry carries the clustering key, its size is paid many times. Suppose a table has 100 million rows and five nonclustered indexes. With a BIGINT key, each entry carries 8 bytes of locator: 100 million x 5 x 8 bytes = about 4 GB. With a 16-byte uniqueidentifier, that becomes 8 GB, and with a composite key of three columns totalling 40 bytes, about 20 GB, before counting the indexes' own keys. Bigger indexes mean more pages to read, less of the index in memory and slower everything.
5What Makes a Good Clustering Key
Four properties matter, and each has a reason. Narrow, because the key is copied into every nonclustered index. Unique, because if it is not, SQL Server adds a hidden 4-byte uniquifier to duplicate keys to tell rows apart. Static, because if the key changes, the row must move to a new position in the clustered index and every nonclustered index entry pointing to it must be updated. Ever-increasing, because new rows then go to the end of the index, so inserts fill pages in order instead of splitting pages in the middle.
A BIGINT IDENTITY column meets all four, which is why it is the common default. A random GUID from NEWID() fails the narrow and ever-increasing tests and causes heavy page splits. A natural key such as an email address fails narrow and static. There are good exceptions: a table almost always queried by a date range might be clustered on (created_at, id) to make those range scans fast, accepting a wider key.
6Follow-up questions
Can a clustered index be non-unique?
Yes. SQL Server then adds a hidden 4-byte uniquifier to rows whose key duplicates another, so each row can still be identified. It works, but it makes the key wider for those rows, which is one reason to prefer a unique clustering key.
When would you choose a heap?
Rarely, mostly for staging tables that are bulk loaded and then read once in full, where ordering gives no benefit. Heaps suffer from forwarded records after updates that grow rows, and their space is harder to reclaim, so for normal OLTP tables a clustered index is the better default.
What does the ever-increasing key cost?
All inserts go to the last page, which can become a hot spot under very high concurrent insert rates, called last-page insert contention. SQL Server 2019 added the index option OPTIMIZE_FOR_SEQUENTIAL_KEY to reduce it; for most systems the benefit of ordered inserts is much larger than that cost.
7Conclusion
In this answer, we saw that a clustered index is the table itself, with full rows in its leaf pages ordered by the clustering key, so there is only one per table. A nonclustered index stores its key plus a row locator, the clustering key or a RID on a heap, and uses key lookups to fetch other columns unless INCLUDE covers them. Because the clustering key is copied into every nonclustered index, it should be narrow, unique, static and ever-increasing, like a BIGINT IDENTITY, and a PRIMARY KEY becomes clustered by default unless declared NONCLUSTERED.
Open with
A clustered index in SQL Server is the table itself. It is a B-tree whose leaf pages hold the complete rows, sorted by the clustering key, so a table can only have one.
Then, if they want more
A table without one is a heap. A nonclustered index is a separate B-tree whose leaf entries hold the index key plus a row locator.
In a clustered table that locator is the clustering key, so finding a row through a nonclustered index means a seek there and then a key lookup into the clustered index, unless the index covers the query with INCLUDE columns. On a heap the locator is a RID, a file, page and slot address.
The choice of clustering key matters because it is copied into every nonclustered index. On a hundred million row table with five indexes, going from an 8-byte bigint to a 16-byte GUID adds about four gigabytes.
So a good key is narrow, unique, otherwise SQL Server adds a 4-byte uniquifier, static, so rows and index entries never have to move, and ever-increasing, so inserts append at the end instead of splitting pages. A BIGINT IDENTITY meets all four.
I would also mention that declaring a PRIMARY KEY creates the clustered index by default, so if we want to cluster on something else, like a date for range queries, we declare the key NONCLUSTERED.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is a clustered index in SQL Server, how does it differ from a nonclustered index...": https://scrivio-interview-library.netlify.app/databases/oracle-and-sql-server/a190eac06a/