Skip to content

Instantly share code, notes, and snippets.

@Pzixel
Created March 24, 2016 08:46
Show Gist options
  • Save Pzixel/9904b546d91320f4e317 to your computer and use it in GitHub Desktop.
Save Pzixel/9904b546d91320f4e317 to your computer and use it in GitHub Desktop.
Rebuilds indices in all tables in DB
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