Skip to content

Instantly share code, notes, and snippets.

@Sebazzz
Created January 21, 2017 12:28
Show Gist options
  • Save Sebazzz/bbf65cba726d78cd79a985a4ea1e008e to your computer and use it in GitHub Desktop.
Save Sebazzz/bbf65cba726d78cd79a985a4ea1e008e to your computer and use it in GitHub Desktop.
SQL script to reindex all tables in your tables
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