Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all SQL server versions rebuild indexes automatically or have a default rebuild criteria?

Do all SQL server versions rebuild indexes automatically or have a default rebuild criteria? I understand statistics are rebuilt automatically but not sure if indexes do as well.

like image 846
thiswayup Avatar asked Feb 24 '09 12:02

thiswayup


People also ask

Does SQL Server automatically rebuild indexes?

The SQL Server Database Engine automatically maintains indexes whenever insert, update, or delete operations are made to the underlying data. Over time these modifications can cause the information in the index to become scattered in the database (fragmented).

How do I know if my SQL Server index needs to be rebuilt?

Microsoft recommends fixing index fragmentation issues by rebuilding the index if the fragmentation percentage of the index exceeds 30%, where it recommends fixing the index fragmentation issue by reorganizing the index if the index fragmentation percentage exceeds 5% and less than 30%.

How often should you rebuild indexes in SQL Server?

There's a general consensus that you should reorganize ("defragment") your indices as soon as index fragmentation reaches more than 5 (sometimes 10%), and you should rebuild them completely when it goes beyond 30% (at least that's the numbers I've heard advocated in a lot of places).

How does index rebuild work in SQL Server?

Using SQL Server Management Studio: Expand the specific table. Expand the Indexes node. Right-click on the fragmented index and select Rebuild or Reorganize option in the context menu (depending on the desired action): Click the OK button and wait for the process to complete.


1 Answers

Rebuilding of indexes is not supported automatically in any version of Microsoft SQL Server - the reason being is that rebuilding indexes can potentially be very expensive operations, and so need careful scheduling and planning.

In many environments special scripts will be written to handle this, for example:

http://weblogs.sqlteam.com/tarad/archive/2008/09/03/Defragmenting-Indexes-in-SQL-Server-2005.aspx

Note that whilst SQL can automatically update statistics for you in many cases there is a performance gain to be had by managing these more carefully as well.

like image 155
Chris Avatar answered Oct 20 '22 04:10

Chris