The command to reindex is different for SQL2000 to SQL2005 and 2008:
- SQL 2000 uses the DBCC REINDEX command and
- SQL2005 uses the ALTER INDEX ALL ON
REBUILD
Example:
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
-- SQL 2000
--DBCC DBREINDEX(@TableName,' ',90)
-- SQL 2005/2008
EXEC('ALTER INDEX ALL ON ' + @tablename + ' REBUILD')
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
No comments:
Post a Comment