Table Sizes and Indexes such as Task Pad View

Table Sizes and Indexes such as Task Pad View

This tip was submitted to the SearchWin2000.com tip exchange by Jennifer Perez. Please let other users know how useful it is by rating it below.


Table Sizes and Indexes such as Task Pad View in SQL Server 2000 display valuable information regarding database size/indexes, but do not allow you to easily move that information from Enterprise Manager into something else. The below code is the same code that Enterprise Manager uses to retrieve its data, and is very helpful in determining database bottlenecks or when to federate.

--Start Script --
select sysTableTemp.UsersName + '.' + sysTableTemp.ObjectsName 
as CompleteName,  sysTableTemp.IndexName, sysTableTemp.rows,  
case when sysTableTemp.indid  =  1 Then 1
  Else 0
 End as IsClusteredIndex,
 (case
  when sysTableTemp.indid > 1 and sysTableTemp.indid <> 255 
   Then pageTableTemp.PageSize * sysTableTemp.NonClusteredDataUsed end) as 
NonClusteredDataUsed, (pageTableTemp.PageSize * (isnull(sysTableTemp.AllData,
 0))) As DataSizeUsed,
  ( case 
   when sysTableTemp.indid  =  1 
    Then pageTableTemp.PageSize * 
     (isnull(sysTableTemp.IndexSizeUsed, 0)- isnull(sysTableTemp.DataSizeUsed,
 0)) end) AS ClustedDataUsed from  ( select  v.low / 1024 as PageSize 
 from    master..spt_values v  
 where   v.number=1 and v.type=N'E' ) as pageTableTemp, 
  (
  select  sysindexes.indid, sysindexes.name as IndexName,  sysobjects.name as
ObjectsName, sysusers.name as UsersName, sysindexes.used as 
NonClusteredDataUsed, tempTable.DataSizeUsed, tempTable.IndexSizeUsed, 
   tempTable.rows, tempTable.AllData 
  from   sysindexes, sysobjects, sysusers, ( 
   select  id, 
    sum(case indid 
     when 0   then sysindexes.dpages 
     when 1   then sysindexes.dpages 
     when 255 then isnull(sysindexes.used, 0) end) as DataSizeUsed, 
    sum(case indid  
     when 0 then isnull(sysindexes.used, 0) 
     when 1 then isnull(sysindexes.used, 0) 
     when 255 then isnull(sysindexes.used, 0) end) as IndexSizeUsed, 
    sum(case indid 
     when 0 then convert(int, rows) 
     when 1 then convert(int, rows) end) as rows, 
    sum(case     
     when indid <= 0 then sysindexes.dpages + isnull(sysindexes.used, 0)     
     else isnull(sysindexes.used, 0) end) as AllData 
   from   sysindexes group by sysindexes.id ) as tempTable 
where  sysindexes.id = sysobjects.id
 and sysusers.uid = sysobjects.uid
 and tempTable.id = sysindexes.id
 and sysobjects.name not like '#%'  
 and OBJECTPROPERTY(sysobjects.id, N'IsMSShipped') <> 1  and OBJECTPROPERTY
(sysobjects.id, N'IsSystemTable') = 0 ) as sysTableTemp order by CompleteName, 
IsClusteredIndex DESC 
--End Script--

This was first published in November 2004

Dig deeper on Windows Operating System Management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close