Index defrag script (21005/2008)


/ Published in: SQL
Save to your folder(s)

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.

URL: http://www.sqlservercentral.com/scripts/Reindex/70985/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.