SQL Server Database Objects Statistics

Hi,

Database objects stats should be up to date for making the right decision of SQL Server optimizer.

 

If database objects stats are not up to date then SQL Server database optimizer will make a wrong decision for execution plan of transaction.

You can check all database objects stats with following query.

 

SELECT 
object_name(si.[object_id]) AS [TableName]
, CASE 
WHEN si.[stats_id] = 0 then 'Heap'
WHEN si.[stats_id] = 1 then 'CL'
WHEN INDEXPROPERTY ( si.[object_id], si.[name], 'IsAutoStatistics') = 1 THEN 'Stats-Auto'
WHEN INDEXPROPERTY ( si.[object_id], si.[name], 'IsHypothetical') = 1 THEN 'Stats-HIND'
WHEN INDEXPROPERTY ( si.[object_id], si.[name], 'IsStatistics') = 1 THEN 'Stats-User'
WHEN si.[stats_id] BETWEEN 2 AND 1004 THEN 'NC ' + RIGHT('00' + convert(varchar, si.[stats_id]), 3)
ELSE 'Text/Image'
END AS [IndexType]
, si.[name] AS [IndexName]
, si.[stats_id] AS [IndexID]
, CASE
WHEN si.[stats_id] BETWEEN 1 AND 250 AND STATS_DATE (si.[object_id], si.[stats_id]) < DATEADD(m, -1, getdate()) 
THEN '!! More than a month OLD !!'
WHEN si.[stats_id] BETWEEN 1 AND 250 AND STATS_DATE (si.[object_id], si.[stats_id]) < DATEADD(wk, -1, getdate()) 
THEN '! Within the past month !'
WHEN si.[stats_id] BETWEEN 1 AND 250 THEN 'Stats recent'
ELSE ''
END AS [Warning]
, STATS_DATE (si.[object_id], si.[stats_id]) AS [Last Stats Update]
, no_recompute
FROM sys.stats AS si
WHERE OBJECTPROPERTY(si.[object_id], 'IsUserTable') = 1 and STATS_DATE (si.[object_id], si.[stats_id]) is not null
AND (INDEXPROPERTY ( si.[object_id], si.[name], 'IsAutoStatistics') = 1 
OR INDEXPROPERTY ( si.[object_id], si.[name], 'IsHypothetical') = 1 
OR INDEXPROPERTY ( si.[object_id], si.[name], 'IsStatistics') = 1)
ORDER BY [Last Stats Update] 
go

 

 

Do you want to learn Microsoft SQL Server DBA Tutorials for Beginners, then read the following articles.

https://ittutorial.org/sql-server-tutorials-microsoft-database-for-beginners/

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

5 comments

  1. If you are seeking for the top service to get website visitors to your web page, i advise to use seowebsitetrafficnet. I am using it with a great result. Simply just type seowebsitetrafficnet in google.

  2. First off I would like to say great blog! I had a quick question in which I’d like to ask if you don’t mind. I was curious to know how you center yourself and clear your mind before writing. I have had difficulty clearing my thoughts in getting my ideas out. I do enjoy writing however it just seems like the first 10 to 15 minutes are wasted simply just trying to figure out how to begin. Any suggestions or tips? Thank you!|

  3. My partner and I stumbled over here coming from a different website and thought I might as well check things out. I like what I see so now i am following you. Look forward to looking at your web page repeatedly.|

Leave a Reply

Your email address will not be published. Required fields are marked *