SQL Server script to rebuild all indexes for all tables and all databasesWritten By: Edgewood Solutions Engineers -- 11/6/2007 -- 4 commentsStay info......
SQL 2005
- comment this line
DBCC DBREINDEX(@Table,' ',@fillfactor)
- uncomment these lines
SET @cmd = 'ALTER INDEX ALL ON ' @Table ' REBUILD WITH (FILLFACTOR = ' CONVERT(VARCHAR(3),@fillfactor) ')'
EXEC (@cmd)
Also, I have excluded the system databases, so you can include these or also add other databases to exclude from you index maintenance routines.
Next Steps
- This is a simple base script that could be modified into a stored procedure and also allow you to pass other parameters such as doing an index rebuild or an index defrag.
- Make the index rebuild statements more robust with other options.
- You could also modify this to read from a table that you create to identify which databases you want to run this against instead of using the sysdatabases table.
- Take a look at these other index related tips
5/5 首页 上一页 3 4 5 |