Rebuilding Indexes on SQL Server

It is quite rare to need to rebuild the indexes on an SQL Server but it does happen. When it does, it is quite easy to rebuild an index using SQL Server Management Studio.

Open up the node for the tables in the database and right click on the Indexes folder and select “Rebuild All”. That presents a window with a list of indexes showing the fragmentation. Click on OK to rebuild all the indexes.

If you need to rebuild all of the indexes in a database with many tables, the following simple script performs the rebuild for each table.

   EXEC sp_MSforeachtable 'ALTER INDEX ALL ON ? REINDEX'

If you want to rebuild all the indexes with a custom fill factor then see the script in the following article.

Tagged with:
Posted in Development

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: