lunes, 17 de agosto de 2020

ACTUALIZAR ESTADISTICAS SQL (TODAS LAS TABLAS)

 ACTUALIZAR ESTADISTICAS SQL (TODAS LAS TABLAS)

SET NOCOUNT  ON

DECLARE  @SQLcommand NVARCHAR(512),

         @Table      SYSNAME

 

DECLARE curAllTables CURSOR  FOR

SELECT table_schema + '.[' + table_name + ']'

FROM   information_schema.tables

WHERE  TABLE_TYPE = 'BASE TABLE'

order by table_name

 

OPEN curAllTables

 

FETCH NEXT FROM curAllTables

INTO @Table

 

WHILE (@@FETCH_STATUS = 0)

  BEGIN

    PRINT N'UPDATING STATISTICS FOR TABLE: ' + @Table

    SET @SQLcommand = 'UPDATE STATISTICS ' + @Table + ' WITH FULLSCAN'

    EXEC sp_executesql @SQLcommand

     

    FETCH NEXT FROM curAllTables

    INTO @Table

  END

CLOSE curAllTables

DEALLOCATE curAllTables

SET NOCOUNT  OFF

GO


No hay comentarios:

Publicar un comentario

Comenta cualquier duda o recomendatorio.