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!!
EXEC sp_MSforeachtable @command1=”print ‘?’ DBCC DBREINDEX (‘?’, ‘ ‘, 80)”