Created
January 21, 2017 12:28
-
-
Save Sebazzz/bbf65cba726d78cd79a985a4ea1e008e to your computer and use it in GitHub Desktop.
SQL script to reindex all tables in your tables
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
DECLARE @TableName nvarchar(255) | |
DECLARE TableCursor CURSOR FOR | |
SELECT table_name FROM information_schema.tables | |
WHERE table_type = 'base table' And TABLE_SCHEMA = 'dbo' | |
OPEN TableCursor | |
FETCH NEXT FROM TableCursor INTO @TableName | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
PRINT CONCAT('Reindexing: ',@TableName,'...') | |
DBCC DBREINDEX (@TableName,' ',0) WITH NO_INFOMSGS | |
FETCH NEXT FROM TableCursor INTO @TableName | |
END | |
CLOSE TableCursor | |
DEALLOCATE TableCursor | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment