SELECT t.Name,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
sys.partitions p ON t.object_id = p.OBJECT_ID
INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id
GROUP BY t.Name
HAVING SUM(a.used_pages) > 0
ORDER BY TotalSpaceKB Desc
No words wasted! Getting to the point about the work I do, the problems I deal with, and some links to posts about where I work.
Translate
Friday, December 19, 2025
TSQL - Simple Table Size Query
Simple query for table size information.
Subscribe to:
Comments (Atom)