Reorganising Indexes & Rebuilding Indexes

Discussion in 'Databases' started by Will1968, Nov 14, 2011.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. This might sound daft (sorry really daft) but does DASP Reorganising Indexes & Rebuilding Indexes as part of its general maintenance procedures for its SQL Servers?

    Thanks,

    Will
     
  2. mjp

    mjp

    No. I don't think most users would appreciate intrusive maintenance like that.
     
  3. Thank you for the reply.

    I have found a script to run against my all my tables that rebuilds my indexes.

    But when I run the 'Index Physical Statistics' report after I running the script it still says that I need to rebuild or reorganise the same indexes that it said before.

    Can you tell me why this is the case?

    I even tried rebuilding the indexes by clicking through (sql svr Mangt Studio) on the table to the indexes and right clicking 'rebuild indexes' to no avail.

    This is the script ...

    DECLARE @TableName VARCHAR(255)
    DECLARE @sql NVARCHAR(500)
    DECLARE TableCursor CURSOR FOR
    SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName
    FROM sys.tables
    OPEN TableCursor
    FETCH NEXT FROM TableCursor INTO @TableName
    WHILE @@FETCH_STATUS = 0
    BEGIN
    print @TableName
    SET @sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD'
    EXEC (@sql)
    FETCH NEXT FROM TableCursor INTO @TableName
    END
    CLOSE TableCursor
    DEALLOCATE TableCursor
    GO

    Many thanks,

    Will
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page