How to rebuild a SQL Server index?

Maintain the indexes is vital to keep a database up to speed with optimal performance. To rebuild an index use the command to alter and rebuild. Technically rebuilding the index delete it and then create it again. After that, the index as no more fragmentation and the index rows are reordered in adjacent pages. But how to rebuild a SQL Server index?

How to rebuild an existing SQL index to optimize query performance ?

Let’s consider the index from the first article of the index series to manage the performance of the sales queries on the year and month. Use the following SQL code to rebuild the index with default options.

ALTER INDEX indexYearMonth ON [dbo].[SALES] REBUILD;

The article shows how to rebuild a SQL Server index. The alter index official documentation explains in depth the features and possibilities of the index rebuild but also the advantages and drawbacks.

Be the first to comment

Leave a Reply

Your email address will not be published.