Posted on Leave a comment

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.