Index all tables in one shot
Here’s a nice little snippet of T-SQL code that will reindex all tables in the database with one line of code:
EXEC sp_msForEachTable @COMMAND1= 'DBCC DBREINDEX ( "?")'
Keep in mind that the DBCC DBREINDEX command will put a lock on the table while it does its thing, so you may not want to do this during peak times. But from time to time, you may find need to reindex all of the tables in a database in one fell swoop, and this’ll do it.
(Found here)


