Monday, December 5, 2011

Update Statistics

DECLARE @tabs TABLE (  id int identity(1,1) not null
                     , tabname sysname not null );

DECLARE @i int
      , @tabname sysname;

   INSERT INTO @tabs ( tabname )
        SELECT name
          FROM sysobjects
         WHERE type = 'U';

SELECT @i = max(id) FROM @tabs;

WHILE @i > 0
 BEGIN
   SELECT @tabname = tabname FROM @tabs WHERE id = @i
   PRINT 'UPDATE STATISTICS ' + @tabname + ' WITH ALL'
   SET @i = @i - 1
 END;

GO

No comments:

Post a Comment