Thursday, October 19, 2006

Find PI Statistics

The below SQL helps to identify if we have stats defined on the PI columns,

select tblstat.databasename,
tblstat.tablename,
tblstat.StatStatus,
tblsize.currentperm,
sum(tblsize.currentperm) over (partition by StatStatus order by StatStatus)
from (
select Databasename,
Tablename,
case when indexstatistics is null
then 'PI Stats Not Defined'
else 'PI Stats Defined'
end as StatStatus
from DBC.IndexStats
where columnposition = 1 and
indextype = 'P'
) tblstat
inner join
(
select databasename,
tablename,
max(currentperm) * count(*) as CurrentPerm
from dbc.tablesize
group by 1,2
) tblsize
on tblstat.databasename = tblsize.databasename and
tblstat.tablename = tblsize.tablename
;

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home