How To Obtain The Size Of All Tables In A SQL Server Database
How to know the space used by each table without using Management Studio's table properties.
SQL Server gives you everything you need with its Stored Procedure sp_spaceused. Unfortunately this SP does not support iterating over all tables in a database, so we needed to leverage another (undocumented) Stored Procedure sp_msForEachTable.
SET NOCOUNT ON
DBCC UPDATEUSAGE(0)
-- DB size. EXEC sp_spaceused
-- Table row counts and sizes. CREATE TABLE #t
(
[name] NVARCHAR(128),
[rows] CHAR(11),
reserved VARCHAR(18),
data VARCHAR(18),
index_size VARCHAR(18),
unused VARCHAR(18)
)
INSERT #t EXEC sp_msForEachTable 'EXEC sp_spaceused ''?'''
SELECT *
FROM #t
-- # of rows. SELECT SUM(CAST([rows] AS int)) AS [rows]
FROM #t
DROP TABLE #t
Source - http://therightstuff.de/CommentView,guid,df930155-f60f-4f56-ab33-f1352ff091a1.aspx