|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 9:23 AM
Points: 1,288,
Visits: 2,996
|
|
Please do remember that sysindexes.rowcnt is only as correct as your latest indexes and stats are up to date. If you have not done this in a while then that column will not be correct.
"Technology is a weird thing. It brings you great gifts with one hand, and it stabs you in the back with the other. ... "
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 9:23 AM
Points: 1,288,
Visits: 2,996
|
|
After conversing with SanDroid, I have amended this query slightly so that the schema name and indid is displayed as well. Not all of you may need to see all of this detail. If so, just filter it out. Notice the sysusers join doesn't always match up sometimes.
SELECT sys.schemas.name as [Schema Name], sysusers.name as TABLE_USER, sysobjects.name as TABLE_NAME, sysindexes.rowcnt as ROWS, sysindexes.indid as [Index], sum(case when sysindexes.indid in (0, 1, 255) then convert(dec(15),reserved*8)else 0 end) as RESERVED_Kb, sum(case when sysindexes.indid < 2 THEN convert(dec(15),dpages*8) ELSE 0 END) + sum(case when sysindexes.indid = 255 THEN convert(dec(15),used*8) ELSE 0 END) AS DATA_Kb, (sum(case when sysindexes.indid in (0, 1, 255) then convert(dec(15),used*8) ELSE 0 END) - sum(case when sysindexes.indid < 2 THEN convert(dec(15),dpages*8) ELSE 0 END) - sum(case when sysindexes.indid = 255 THEN convert(dec(15),used*8) ELSE 0 END)) AS INDEX_SIZE_Kb, sum(case when sysindexes.indid in (0, 1, 255) then convert(dec(15),(reserved - used)*8) else 0 end) AS UNUSED_Kb FROM sysobjects (NOLOCK) INNER JOIN sysindexes (NOLOCK) ON sysobjects.id = sysindexes.id LEFT JOIN sysusers (NOLOCK) ON sysobjects.uid = sysusers.uid LEFT JOIN sys.schemas (NOLOCK) ON sysobjects.UID = sys.schemas.schema_id WHERE (sysobjects.type = 'U') AND (sysindexes.indid = 1) group by sys.schemas.name,sysusers.name, sysobjects.name,sysindexes.rowcnt,sysindexes.indid ORDER BY ROWS DESC, [SCHEMA NAME],TABLE_NAME GO
"Technology is a weird thing. It brings you great gifts with one hand, and it stabs you in the back with the other. ... "
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:29 PM
Points: 182,
Visits: 952
|
|
TravisDBA,
I notice some tables where still being skipped after your latest changes. The query excludes tables without a clustered index.
To include them, modify the where clause to use (sysindexes.indid <= 1) .
The Adventureworks database has a few tables that use HEAP instead of a clustered index. This makes it a good database to test the query against.
David Bird
My PC Quick Reference Guide
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 9:23 AM
Points: 1,288,
Visits: 2,996
|
|
Yes,you can do that or just comment that clause out and you will see more...
"Technology is a weird thing. It brings you great gifts with one hand, and it stabs you in the back with the other. ... "
|
|
|
|