Tuesday 8 November 2011

Sql for finding the frgmentaion of the tables in databse

select o.name "Table Name",i.name "Table/Index Name",i.indid,
Case when i.indid=0 then
 derived_stat(o.name,i.indid,"dpcr")
else  derived_stat(o.name,i.indid,"ipcr")
end "CLUSTER RATIO",
derived_stat(o.name,i.indid,"lgio") "Large IO Effeciency",
derived_stat(o.name,i.indid,"sput") "Space Utilization",
s.pagecnt "Pages",
s.rowcnt "Rows",
s.forwrowcnt "forward row count",
s.delrowcnt "Deleted ROw Count"
--,ss.moddate "Last Update Stats Run",
--ss.sequence
from sysindexes i,sysobjects o, systabstats s  --,sysstatistics ss
where o.id=i.id and o.id = s.id   --and o.id=ss.id
and o.type = 'U'
order by s.rowcnt desc


Also see the new post for Fragmentation and its new Resolution steps.

1 comment: