Bygga om index i en SQL-DB

Så här bygger man om alla index i en SQL-databas.

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)
                PRINT ‘Reindex INDEX ON TABLE: ‘ + @TableName
                FETCH NEXT FROM TableCursor INTO @TableName
        END

CLOSE TableCursor

DEALLOCATE TableCursor
 

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>