This SQL for use with Microsoft SQL Server is a little better than the standard EXEC sp_MSforeachtable @command1=”EXEC sp_spaceused ‘?'”

SELECT
t.NAME AS TableName,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id
WHERE
t.NAME NOT LIKE 'dt%'
GROUP BY
t.NAME
ORDER BY
(sum(a.total_pages) * 8) / 1024 desc

Same results, but easier to read and ordered by biggest offenders first. Note that the space taken includes any indices on the table.

Archives