E-Mail:

Getting Space Used For Tables

I have been looking for a more efficient way of getting space used requirements for all of my tables in a given database.  It seems like Microsoft has answered my prayers.  Microsoft has now given us the sp_MSforeachtable stored procedure.  This procedure is not currently documented within BOL.  The T-SQL script below demonstrates how to use this procedure to retrieve space utilization for all tables within a given database.  If you have a better or different way please post and let us know!

CREATE TABLE #TemptableforspaceUsed
(name SYSNAME,
rows bigINT,
reserved VARCHAR(20),
data VARCHAR(20),
index_size VARCHAR(20),
unused VARCHAR(20))
GO
INSERT #TemptableforspaceUsed
EXEC sp_MSforeachtable ’sp_spaceused ”?”’

update #TemptableforspaceUsed
set reserved=replace (reserved,’KB’,”)

select top 10 name, reserved

from #TemptableforspaceUsed

order by convert(bigint,reserved) desc
drop table #TemptableforspaceUsed

What Do You Think?

 

Want to Start a Blog Here for Free?

Are you an expert in one subject or another? If your goal is to help others and dispense hard-earned information back to the community, stake a claim on your very own Lockergnome blog today! You can write about anything - no matter the topic. Sign-up to start blogging!

Administration - Jan 2, 2008

Reporting Services On A Cluster

Programming - Dec 14, 2007

Victim Of Parameter Sniffing?

58 queries / 0.293 seconds.