Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Last active February 22, 2018 17:29
Show Gist options
  • Save jbubriski/fb6a441e0b6f51acbee66a2b30a42a2c to your computer and use it in GitHub Desktop.
Save jbubriski/fb6a441e0b6f51acbee66a2b30a42a2c to your computer and use it in GitHub Desktop.
This will rebuild all the indexes in your DB.
-- From https://gallery.technet.microsoft.com/scriptcenter/Script-for-rebuilding-all-8d079754
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