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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to Update Statistics On Tables, which needs to

Author  Topic 

shaileshpatangay
Starting Member

4 Posts

Posted - 2009-06-29 : 09:44:06
How to Update Statistics On Tables, which needs to be updated.

Following columns are returned from this report

TableName : Name for the Table.
IndexName : Name for the index.
Rows Modified : Number of Rows Modified.
ActionRequired : Healing Action required, Generates the sql Command to be executed on the DB.

Following is the Sql Statement used to abstract the above required Information.
This report would be ran against each user database and would be having a
Inclusion and Exclusion List, which would be eliminate and include table names
As required.



Statement

SELECT

o.name AS TableName

, i.name AS IndexName

, i.rowmodctr AS RowsModified

,'update statistics ' || O.NAME As ActionRequired

FROM

sysobjects o

JOIN sysindexes i ON o.id = i.id

WHERE

i.rowmodctr > 0

and o.xtype = 'U'

and i.createddate in (select max(createddate) from mssysindexes where createddate < o.createddate)

and DatabaseOID = ‘$DatabaseOID$’

and i.name in (‘$InclusionList$’)

and i.name not In (‘$Exclusion List$’)

ORDER BY

i.rowmodctr DESC



Example Audit Report :

********************************************************************************************************************

TableName IndexName RowsModified ActionRequired

********************************************************************************************************************

CounterStat PK_CounterStat 99 UPDATE STATISTICS CounterStat

Contact PK_Contact 57 UPDATE STATISTICS Contact

dtproperties pk_dtproperties 46 UPDATE STATISTICS dtproperties

Scripts Scripts 19 UPDATE STATISTICS Scripts

ContactGroup PK_ContactGroup 15 UPDATE STATISTICS ContactGroup

DiskSpace DiskSpace 12 UPDATE STATISTICS DiskSpace

TargetServerLogins TargetServerLogins 11 UPDATE STATISTICS TargetServerLogins

********************************************************************************************************************


cheers
shailesh patangay

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-06-29 : 13:03:45
Why don't you just use sp_updatestats which knows which need to be updated already?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -