Rebuild all index in a database

Several times my colleagues asked me about rebuilding all indices in a database. While there are several solution available, I like to use the one below. Please note that sp_MSforeachtable is undocumented but internal so we can expect a much better performance than our own cursor.

None the less, this has helped me alot, I hope it helps you too!!


USE <DBName>
EXEC sp_MSforeachtable @command1=”print ‘?’ DBCC DBREINDEX (‘?’, ‘ ‘, 80)”
EXEC sp_updatestats

  1. 10 years ago

Leave a Reply

Your email address will not be published. Required fields are marked *