Get Size of tables in MS SQL Part 2

One of the most hit articles on my blog is how to get the size of MS SQL tables with CF. I have always meant to get back to the idea and make a non CF based solution. Here is a different / better way to get the table sizes:

DECLARE @SQL VARCHAR(255)
SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'
EXEC(@SQL)
CREATE TABLE #foo
(
name VARCHAR(255),
rows INT ,
reserved varchar(255),
data varchar(255),
index_size varchar(255),
unused varchar(255)
)
INSERT into #foo
EXEC sp_MSForEachtable 'sp_spaceused ''?'''
SELECT *
FROM #foo
DROP TABLE #foo
I was going to build something very close to the above code but, I found this before I had the time to play at http://www.mydatabasesupport.com/forums/sqlserver-programming/188852-database-table-size.html

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001. Contact Blog Owner