How to rebuild all the indexes on a single table – SQL Server

If you have ever wanted to rebuild all the indexes on a table its pretty simple.

I have had to do this sometimes when troubleshooting a situation and not wanting to run a whole reindexing operation – just target in on one table.

Re-indexing can be a thankless task – remember it is best not to use the built in maintenance tasks if at all possible. Use a custom script that firstly checks for fragmentation levels and either rebuilds or reorganizes as required.

Here is the simple code.

[SQL]
ALTER INDEX ALL ON YourTableName REBUILD
[/SQL]

There it is – Done.

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

1 Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.