Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved 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: 3215 | Views in the last 30 days: 5
 
Related Articles
FORUM

Rebuild Index

Rebuild Index

FORUM

Rebuilding indexes

Rebuilding indexes

FORUM

Index Rebuilding

Index Rebuilding - SQlServer2005

FORUM

INDEX REBUILD

Rebuilding indexes for better performance.

FORUM

Rebuild on NONclustered Index

Rebuild on NONclustered Index

Tags
administration    
indexing    
maintenance    
reindex    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones