sp_statistics for all indexes in all tables...

  • is there a script or command out there that will run sp_statistics against all the indexes in all the tables of a certain database?

     

     

  • MS_foreachtable will run a command against all tables. Might be a way to script it for all indexes.

  • DECLARE  cur_Databases

    CURSOR  FOR

      SELECT CATALOG_NAME

      FROM INFORMATION_SCHEMA.SCHEMATA

      WHERE CATALOG_NAME NOT IN ('master', 'msdb', 'tempdb', 'model', 'pubs', 'Northwind')

     

    DECLARE  @DbName  VARCHAR(50)

    DECLARE  @Buildstring VARCHAR(100)

     

    OPEN  cur_Databases

     

    FETCH  NEXT

    FROM  cur_Databases

    INTO  @DbName

     

    WHILE  @@FETCH_STATUS = 0

      BEGIN

       SET @Buildstring = 'EXEC ' + @DbName + '..sp_updatestats'

       EXEC (@Buildstring)

       FETCH NEXT

       FROM cur_Databases

       INTO @DbName

      END

     

    CLOSE  cur_Databases

    DEALLOCATE cur_Databases

    Give that a go

    Wes

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply