Benefits of clustered indexes

SQL Server stores a table as a heap or as a balanced tree (B-tree). If you create a clustered index, a table is stored as a B-tree. As a general best practice, you should store every table with a clustered index because storing a table as a B-tree has many advantages, as listed here:

  • You can control table fragmentation with the ALTER INDEX command using the REBUILD or REORGANIZE option.
  • A clustered index is useful for range queries because the data is logically sorted on the key.
  • You can move a table to another filegroup by recreating the clustered index on a different filegroup. You do not have to drop the table as you would to move a heap.
  • A clustering key is a part of all nonclustered indexes. If a table ...

Get SQL Server 2017 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.