Friday, May 18, 2012
 

Sentra Support
Minimize




Save as PDF!
Sentra Knowledge Base - Detail
Minimize
Script to show when stats were last updated on a database and other useful info

Script to show when stats were last updated. Shows which stats were auto created and which were user created.


Issue ID : 3814

Priority : Medium

Version : V6.2

--Script to show when stats were last updated
--Shows which stats were auto created and which were user created
--02/01/2009
select
object_name(ss.object_id) as TABLE_NAME,
coalesce(si.type_desc,'***NO INDEX***') as INDEX_TYPE,
case si.is_unique when 1 then 'Y' else 'N' end as UNIQUE_INDEX,
case si.is_primary_key when 1 then 'Y' else 'N' end as PRIMARY_KEY,
case si.is_unique_constraint when 1 then 'Y' else 'N' end as UNIQUE_CONSTRAINT,
ss.name as STATISTIC_NAME,
case when si.name is not null then stats_date(t.object_id, si.index_id)
else stats_date(t.object_id, ss.stats_id)
end as LAST_UPDATE_STATS,
stuff((SELECT ', ' + c.name
FROM sys.stats_columns as sc
inner join sys.columns as c
on sc.object_id = c.object_id
and sc.column_id = c.column_id
WHERE ss.object_id = sc.object_id
and ss.stats_id = sc.stats_id
ORDER BY c.column_id FOR XML PATH('')), 1, 1, '') as INDEX_COLUMNS,
case auto_created when 1 then 'Y' else 'N' end as STAT_AUTO_CREATED,
case user_created when 1 then 'Y' else 'N' end as STAT_CREATED_BY_USER
from sys.stats as ss
inner join sys.tables as t
on object_name(ss.object_id) = t.name
left outer join sys.indexes as si
on ss.name = si.name
where t.is_ms_shipped = 0
order by t.name, coalesce(si.index_id, 999)

 

print






Fast Link >>
Minimize
Sentra Knowledge Base Search
Minimize



 

Follow Insider Technologies Limited Twitter Account TweetsInsider Technologies Limited Spinnaker Court Chandlers Point 37 Broadway Salford Quays Greater Manchester M50 2YR LinkedIn Company GroupJoin the Insider Technologies Limited Group on FacebookHome   |    Markets   |   Solutions   |   Products   |   Services   |   News & Events   |   Support   |   About Us   |   Location   |   Contact Us   |   Site Map   |   LinkedIn
Sentra for LAPS by Logica   |   Thales e-Security Support   |   Sentra for STAR by Software Integrators
   |   RTLX Reactor for BASE24 & eps by ACI Worldwide
RTLX Reactor is a registered trademark of Insider Technologies Limited

Privacy Statement  |  Terms Of Use
Copyright 2012 : Insider Technologies Limited, Manchester. M50 2YR (Near MediaCity UK BBC North ITV)