Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebuilding SQL Indexes - When?

Tags:

tsql

indexing

When should one rebuild indexes? Nightly? Weekly? Hourly?

like image 728
0xB33F Avatar asked May 18 '10 18:05

0xB33F


People also ask

When should you rebuild indexes?

If an index contains less than 100 pages, I will perform no maintenance. If an index is between 10% and 30% fragmented, I will REORGANIZE the index and UPDATE the statistics. If an index is over 30% fragmented, I will REBUILD the index - with no UPDATE STATISTICS , as this is taken care of by the REBUILD .

Does SQL Server rebuild indexes automatically?

The Database Engine automatically modifies indexes whenever insert, update, or delete operations are made to the underlying data.

Why do we rebuild indexes?

Rebuilding an index drops and re-creates the index. This removes fragmentation, reclaims disk space by compacting the pages based on the specified or existing fill factor setting, and reorders the index rows in contiguous pages.

What happens when index is rebuild?

Performing an index rebuild eliminates fragmentation, compacts the pages based on the existing fill factor setting to reclaim storage space, and also reorders the index rows into contiguous pages.


2 Answers

It depends on the fragmentation levels not on the timeframe in general, check out the Automated Index Defrag Script here by Michelle Ufford, it will check the fragmentation levels and only rebuild/reorg when needed

like image 106
SQLMenace Avatar answered Sep 24 '22 16:09

SQLMenace


Run an intelligent script (from SQL Fool) , nightly say, and it will decide to do nothing, defrag or rebuild.

Basically, do the minimum commensurate with your fragmentation levels.

I would run it every night, personally, as a general rule. I'd rebuild stats every night at least.

like image 42
gbn Avatar answered Sep 23 '22 16:09

gbn