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

Posted in

Leave a Reply

Your email address will not be published. Required fields are marked *

Design a site like this with WordPress.com
Get started