devxlogo

Rebuild All Table Indexes in a SQL Server Database with One Command

Rebuild All Table Indexes in a SQL Server Database with One Command

You can use the sp_MSforeachtable undocumented stored procedure to rebuild all indexes in your database. The command iterates through all the tables in a database. It’s best to schedule this so it executes only during CPU idle time and at slow production periods:

sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?')"

devx-admin

Share the Post: