Posted on Leave a comment

sp_MSforeachtable

You can use the sp_MSforeachtable undocumented system stored procedure to accomplish tasks on all tables of a database such as rebuilding indexes or recomputing statistics.

This script rebuilds all indexes with a fillfactor of 80 in every table in the pubs database:

USE pubs
GO

EXEC sp_MSforeachtable @command1=”print ‘?’ DBCC DBREINDEX (‘?’, ‘ ‘, 80)”
GO

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.