Created
January 14, 2014 15:26
-
-
Save eduardosilva/8420059 to your computer and use it in GitHub Desktop.
Script for rebuilding all table indexes in SQL Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://gallery.technet.microsoft.com/scriptcenter/Script-for-rebuilding-all-8d079754 | |
USE DatabaseName --Enter the name of the database you want to reindex | |
DECLARE @TableName varchar(255) | |
DECLARE TableCursor CURSOR FOR | |
SELECT table_name FROM information_schema.tables | |
WHERE table_type = 'base table' | |
OPEN TableCursor | |
FETCH NEXT FROM TableCursor INTO @TableName | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
DBCC DBREINDEX(@TableName,' ',90) | |
FETCH NEXT FROM TableCursor INTO @TableName | |
END | |
CLOSE TableCursor | |
DEALLOCATE TableCursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment