Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 UPDATE_STATISTICS

Author  Topic 

rkc01
Starting Member

43 Posts

Posted - 2002-05-31 : 22:37:11
I wanted to schedule a periodic update stats on all user tables on a 6.5 database. I put this script together.

if object_id('dbo.Update_Statistics') is not null
drop procedure dbo.Update_Statistics
GO

/*******************************************************************************
This procedure updates statistics on all user defined tables in the database.
It has been written for and tested against Microsost SQL 6.5 databases.
Author: Rob Campbell
Date Created: 05/31/02
Date Modified: 05/31/02

Usage example: exec Update_Statistics
*******************************************************************************/

create procedure Update_Statistics
as

set nocount on

declare @tablename varchar(150)


declare table_name cursor for
select 'UPDATE STATISTICS ' + name from sysobjects where type = 'u'
order by name

open table_name

fetch next from table_name
into @tablename


WHILE @@FETCH_STATUS = 0

BEGIN
exec (@tablename)
print @tablename
FETCH NEXT FROM table_name INTO @tablename
END
print ''
print 'All user table statistics have been updated'

CLOSE table_name
DEALLOCATE table_name

   

- Advertisement -