RSS

Reindexing in SQL Server 2008

09 Sep

This is an handy script to rebuild index in SQL Server 2005

–USE DATABASENAME
USE GEN2011;

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

 
Leave a comment

Posted by on September 9, 2011 in SQL Server Index

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s