Monday, March 12, 2012

ReIndexing all Tables in a Database

I need to reindex all tables in my database and would like to do this without using a Cursor. What is the simplest way to achieve this.

Cheers

Nat

Hi Nat,

If you didn't want to use a cursor, you could use the sp_MSForEachTable undocumented proc:

exec sp_msforeachtable "dbcc dbreindex('?')"

Cheers,

Rob

|||

You could also look at SMO for this operation. I have been working with it and have been very impressed. Here is a link to the database class, it will be a good starting point.

http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.database.aspx

No comments:

Post a Comment