SQL Server Interview Question #122

What is a clustered index?

Indexes & Query Performance Senior Advanced

Detailed Explanation

A clustered index determines the logical ordering of rows at the leaf level of the index, where the data pages themselves form the clustered index leaf level. Because a table's rows can be organized this way only once, a table can have only one clustered index.

A clustered key is often used for range queries and primary access patterns. The clustered key should generally be narrow, stable, and preferably ever-increasing when that fits the workload, because it is also included as the row locator in nonclustered indexes.

Code Example

CREATE CLUSTERED INDEX CX_Orders_Id
ON dbo.Orders(Id);