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>
GO
EXEC sp_MSforeachtable @command1=”print ‘?’ DBCC DBREINDEX (‘?’, ‘ ‘, 80)”
GO
EXEC sp_updatestats
GO
Rebuild all index in a database
No comments:
Post a Comment