Tip

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,

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.