Just Learned: Create Indexes with Included Columns #MSSQL

Just read an interesting fact about index creation on Microsoft SQL Server.

Usually, the index pages contain only the values to be indexed (e.g., if you create an index on column X, all the values of X are in the index). However, there is the option to include other (specified) columns in the index:

CREATE NONCLUSTERED INDEX idx_product ON Products.Product (ProductName)
INCLUDE (SKU, ListPrice, ShortDescription, ProductID)

The advantage? The included columns are being stored¬†directly in the index page which means that the data page doesn’t need to be¬†loaded from disc when one of the included columns is being requested.

Leave a Reply

Your email address will not be published. Required fields are marked *