🗄️ Database Design / Normalization
Beginner
What is the difference between a clustered and non-clustered index?
Answer
A clustered index determines the physical storage order of rows in the table — the table data is sorted and stored according to the clustered index key. Each table can have only one clustered index (the primary key is clustered by default in most RDBMS). Row lookup via the clustered index is fastest because the actual data is at the leaf node. A non-clustered index stores index key values and pointers (row locators) to the actual data rows separately — the table data is not reordered. A table can have many non-clustered indexes. Lookups require a pointer follow ("key lookup") after finding the index entry.