SQL Server: T-SQL Script to Rebuild all Indexes of a Database

Sharing one more SQL Server Database Administrator script for rebuilding all Indexes of a Database.

To Rebuild or Reorganize the Indexes is a very common task for DBA.
If Index fragmentation is increasing, periodically It requires to execute Rebuild Index for better performance.

If we want to Rebuild all Indexes of a Database, we should prepare a separate script because using default command we can only perform Rebuild operation on table level.

SQL Server: Script to find Index Average Fragmentation in Percentage

In below script, I commented Fill Factor related changes and If It requires, anyone uncomment and use it.
Please SELECT your database and execute this script.

Note: Database REBUILD INDEX is a very costly operation and It requires an exclusive lock on table so please aware yourself before executing it.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of