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.
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_StatisticsGO/******************************************************************************* 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_Statisticsasset nocount ondeclare @tablename varchar(150) declare table_name cursor forselect 'UPDATE STATISTICS ' + name from sysobjects where type = 'u'order by nameopen table_namefetch next from table_name into @tablenameWHILE @@FETCH_STATUS = 0BEGIN exec (@tablename) print @tablename FETCH NEXT FROM table_name INTO @tablenameEND print '' print 'All user table statistics have been updated'CLOSE table_nameDEALLOCATE table_name |
|
|
|
|