Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


List table space usage and row counts


List table space usage and row counts

Author
Message
Louis Li
Louis Li
SSC-Enthusiastic
SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)

Group: General Forum Members
Points: 182 Visits: 258
Comments posted to this topic are about the item List table space usage and row counts

----------------------------------------------------------------------------------------------
Microsoft Certified Solution Master: Data Platform, Microsoft Certified Trainer
Email: Louis.Li@rrlminc.com | Blog | LinkedIn
tskelley
tskelley
Valued Member
Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)

Group: General Forum Members
Points: 65 Visits: 1157
Many thanks, this is much cleaner than my previous code.

I did add

AND INDEX_ID = 0

to the WHERE clause to keep my name list unique and not show indexes. I mainly needed the table info.



Louis Li
Louis Li
SSC-Enthusiastic
SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)

Group: General Forum Members
Points: 182 Visits: 258
I would use AND INDEX_ID <= 1 when index space is not needed.

Index ID 0 is for heap tables and Index ID 1 is for tables with clustered index.

----------------------------------------------------------------------------------------------
Microsoft Certified Solution Master: Data Platform, Microsoft Certified Trainer
Email: Louis.Li@rrlminc.com | Blog | LinkedIn
chuck.hamilton
chuck.hamilton
SSC-Enthusiastic
SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)

Group: General Forum Members
Points: 102 Visits: 395
tskelley (1/17/2014)
Many thanks, this is much cleaner than my previous code.

I did add

AND INDEX_ID = 0

to the WHERE clause to keep my name list unique and not show indexes. I mainly needed the table info.


I added

AND INDEX_ID in (0,1)

so it shows both tables with and without clustered indexes. (0=heap, 1=clustered index).
mikeg13
mikeg13
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 316
As mentioned here there are indexes shown in the results. Would it make sense if I were to group by the "Name" and do a SUM(reserved_page_count * 8) as space_used_kb to get the total space used for the table (including indexes), and do a MAX(row_count) as row_count to get the number of records?
Louis Li
Louis Li
SSC-Enthusiastic
SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)

Group: General Forum Members
Points: 182 Visits: 258
mikeg13 (1/17/2014)
As mentioned here there are indexes shown in the results. Would it make sense if I were to group by the "Name" and do a SUM(reserved_page_count * 8) as space_used_kb to get the total space used for the table (including indexes), and do a MAX(row_count) as row_count to get the number of records?


Yes, I can see the value of having sum. I had made another script and posted on my blog, check it out if you're interested. Thank you for your suggestion.
Table Space and row count – Version 2

----------------------------------------------------------------------------------------------
Microsoft Certified Solution Master: Data Platform, Microsoft Certified Trainer
Email: Louis.Li@rrlminc.com | Blog | LinkedIn
danaanderson
danaanderson
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 183
The total space used in version 2 doesn't match any of the space used values in version 1. The values in version 1 seem to be considerably higher in all cases. Is this because something is being eliminated from the results calculations? The row counts match.

Dana
Louis Li
Louis Li
SSC-Enthusiastic
SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)

Group: General Forum Members
Points: 182 Visits: 258
danaanderson (1/18/2014)
The total space used in version 2 doesn't match any of the space used values in version 1. The values in version 1 seem to be considerably higher in all cases. Is this because something is being eliminated from the results calculations? The row counts match.

Dana


Thanks Dana for pointing it out, I made a mistake. It has been fixed now.

----------------------------------------------------------------------------------------------
Microsoft Certified Solution Master: Data Platform, Microsoft Certified Trainer
Email: Louis.Li@rrlminc.com | Blog | LinkedIn
danaanderson
danaanderson
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 183
Louis&Sql (1/18/2014)
danaanderson (1/18/2014)
The total space used in version 2 doesn't match any of the space used values in version 1. The values in version 1 seem to be considerably higher in all cases. Is this because something is being eliminated from the results calculations? The row counts match.

Dana


Thanks Dana for pointing it out, I made a mistake. It has been fixed now.


You're welcome. Ah, I should have noticed the missing [*8] in the calculations.

Dana
Carolyn S. White
Carolyn S. White
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 25
Please excuse my ignorance.
I need to change this how?
I get the error
Incorrect syntax near 'o'.
I tried changing SCHEMA_NAME to the name of the schema for the particular database. That didn't help.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search