Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Index defrag script (21005/2008)

By Gregory Ferdinandsen,

It's pretty straightforward, with plenty of notes in the SP.

It can either rebuild/reorg all databases or just a selected database. Options are there to prevent small indexes from being redone (there is not much point in rebuilding an idex with only a few pages). You can also prevent it from reindexing large indexes, one that you may prefer to do manually. If the edition of SQL supports it, it will do online rebuilds. You can also prevent index from being rebuilt that are over a certain threshold, either in pages or percentage (you may want to do manually large indexes manually).

You can set your own threshold for reorg versus rebuild (defaults to 5/30). There is also an option to change the recovery model to simple for the duration of the action.

The only time this may fail is if your server is case sensitive, I did not build in the checks to allow for that.

If you want to rebuild all indexes with a new fillfactor, just set the @ReOrgThreshold to 1.01 and @ReBuildThreshold to 1.02...or do it manually.

Not much else to add, the SP has a good bit of documentation.

Total article views: 3298 | Views in the last 30 days: 2
 
Related Articles
FORUM

Rebuild Index

Rebuild Index

FORUM

Rebuilding indexes

Rebuilding indexes

FORUM

Index Rebuilding

Index Rebuilding - SQlServer2005

FORUM

Rebuild on NONclustered Index

Rebuild on NONclustered Index

FORUM

INDEX REBUILD

Rebuilding indexes for better performance.

Tags
administration    
indexing    
maintenance    
reindex    
 
Contribute