Skip to content

Rebuild All Indexes On A Database In One Call

June 9, 2014
tags:

Normally I’d leave this sort of thing to a DB to deal with but I stumbled on this a few months back and thought it was rather clever.

USE MyDbName
GO
EXEC sp_MSforeachtable @command1=”print ‘?'”, @command2=”ALTER INDEX ALL ON ? REBUILD WITH (ONLINE=OFF)”
GO
SELECT * FROM sys.Dm_db_index_physical_stats(Db_id(‘MyDbName’),NULL,NULL,NULL,NULL) — This bit just tells you the results

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: