Mark Nicholson

public class Universe { public Universe(params object[] values) { throw new NotSupportedException(); } }

[SQL Server™] How to: Reindex an entire database

I often run into small, annoying little problems as I'm sure most people working in IT do at some point, so I decided to start blogging the solutions. No matter how insignificant they may seem, they may save someone an hour or two of Google'ing for the answer.

How to: Reindex an entire database on SQL Server 2000 or SQL Server 2005 in a single statement:

EXEC [sp_MSforeachtable] @command1="DBCC DBREINDEX('?')"

If you want to receive progress messages while it is running, try this version:

EXEC [sp_MSforeachtable] @command1="RAISERROR('DBCC DBREINDEX(''?'') ...',10,1) WITH NOWAIT DBCC DBREINDEX('?')"

Posted: Aug 18 2007, 10:31 AM by markn | with no comments
Filed under:
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: