SQL Clone
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-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 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
SSC-Addicted
SSC-Addicted (459 reputation)SSC-Addicted (459 reputation)SSC-Addicted (459 reputation)SSC-Addicted (459 reputation)SSC-Addicted (459 reputation)SSC-Addicted (459 reputation)SSC-Addicted (459 reputation)SSC-Addicted (459 reputation)

Group: General Forum Members
Points: 459 Visits: 1189
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-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 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-Addicted
SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)SSC-Addicted (440 reputation)

Group: General Forum Members
Points: 440 Visits: 408
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
Mr or Mrs. 500
Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)Mr or Mrs. 500 (554 reputation)

Group: General Forum Members
Points: 554 Visits: 322
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-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 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
SSC Veteran
SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)

Group: General Forum Members
Points: 256 Visits: 191
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-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 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
SSC Veteran
SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)SSC Veteran (256 reputation)

Group: General Forum Members
Points: 256 Visits: 191
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
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 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