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

In this post, I am sharing 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 executing Rebuild Index for better performance.

If we want to Rebuild all Indexes of a Database, we should build and generate the 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 anyone wants, they uncomment it.
Please SELECT your database and execute the below 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.

Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of