MS SQL reindexing Database

You guys might be already know this:

Script to automatically reindex all tables in a database. Please note that this might take up to 12 hours. I run this on my database and took 4 hours. the database size was 21 G. You also need (size of your db * 2) free space to run this…

USE Databasename

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
PRINT ‘Reindexing’ + @TableName
DBCC DBREINDEX(@TableName,’ ‘,90)
FETCH NEXT FROM TableCursor INTO @TableName
END

CLOSE TableCursor

DEALLOCATE TableCursor

[ad]

You must be logged in to post a comment.