December 6, 2012 at 1:44 pm
I am building a data mart for server metrics. Using the various system views I need to find disk space used for each table in each database. The same goes for columns and indexes. Any clues how to find this?
December 6, 2012 at 1:53 pm
sp_spacedused 'Tablename' is pretty good for at a glance info.
sp_spaceused 'MyTable'
/*
name rows reserved data index_size unused
MyTable 587 576 KB 320 KB 200 KB 56 KB
*/
did you need it for just specific items, or every table? there's some system views to get that on a database wide basis
Lowell
December 6, 2012 at 1:55 pm
I need it for every table, column, and index on all of our servers plus other things that I have already figured out how to find.
December 6, 2012 at 2:00 pm
Try sys.dm_db_partition_stats for table and index.
Column space usage isn't stored. Best you'll be able to do is average size of the column * number of rows.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 6, 2012 at 2:04 pm
That's not looking too helpful either. Damn I was hoping that this would be a lot easier to find and I was just missing something.
December 6, 2012 at 2:13 pm
look in the scripts section; there's lots of examples where somone has wrapped sp_spacedused in a cursor,
For an example of using sys.dm_db_partition_stats that gail mentioned, if you pick apart this one:
http://www.sqlservercentral.com/scripts/Table+Size/63422/
you can get the used_page_count * page size of 8192 gets you they size in bytes; divide by whatever is good for you to get it into gig/meg/kilo.
it has tables/vs each index separately.
Lowell
December 6, 2012 at 3:01 pm
cacapo (12/6/2012)
That's not looking too helpful either. Damn I was hoping that this would be a lot easier to find and I was just missing something.
What's hard about a DMV that lists sizes per table and index?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply