What is the physical difference between clustered and non-clustered indexes in how data is stored on disk, and why can you only have one clustered index?
Last updated
A clustered index stores the full rows in its B-tree leaf pages, ordered by the key: the table itself is the index.
A non-clustered index is a separate B-tree holding the key plus a row locator (clustered key or row ID). Extra columns need a lookup back to the table, and you can have many per table.
Only one clustered index is possible because rows can be physically sorted in just one order. Choose its key carefully since it's embedded in every non-clustered index.
- https://learn.microsoft.com/en-us/sql/relational-databases/indexes/clustered-and-nonclustered-indexes-described?view=sql-server-ver17
- https://learn.microsoft.com/en-us/answers/questions/2121345/cluster-index
- https://learn.microsoft.com/en-us/sql/relational-databases/indexes/indexes?view=sql-server-ver17
- https://www.sqlservercentral.com/blogs/sql-server-storage-internals-part-5-properties-of-clustered-and-non-clustered-index-pages
- https://dev.to/devcorner/clustered-vs-non-clustered-index-in-databases-5gfj
- https://medium.com/@lucasmedja1/clustered-vs-non-clustered-indexes-a-deep-dive-032c241b6efc
- https://www.solarwinds.com/database-optimization/clustered-vs-non-clustered-index