How Data and Indexes Are Stored

Rows from a table are stored on pages. A table consists of a group of pages linked together in a chain. As a table grows, a new page is added from a pool of available pages that are randomly distributed throughout the file. Available pages are allocated from unused pages in the device or from pages that have been released because of deletions. The pages that make up the table are not in any physical order, though they have been linked together with pointers that point to the physical position of the next or previous page. The pointers of linked pages are stored in each page header, as illustrated in the following diagram.

The indexes in SQL Server are made up of pages that form a branching structure known as a B-tree. The starting page contains ranges of values within the table. Each range on the starting page branches to another page that contains a more detailed range of values in the table. In turn, these index pages branch out to more layers, which increase the number of pages in the layer and narrow the range of data on each page.

The branching index pages are called node pages. The final layer in the branching structure is called the leaf layer. In a unique, nonclustered index, the ranges on each leaf layer page point to a specific row of data in the table, and the data is stored separately from the index. In a clustered index, the leaf layer is made up of the data pages themselves, because the data is stored with the index, in the physical order specified in the index.

The following diagram illustrates the page structures of clustered and nonclustered indexes.