Chris Straw
SHARE:

SQL Server Table Sizes

With Azure SQL, you can’t run the table size reports, so I use this script (as a view) to see the size of all the tables in the database.

SELECT CONCAT('[', sm.name, '].[', o.name, ']') AS [Table],
       MAX(s.row_count) AS [Rows],
       SUM(s.reserved_page_count) * 8.0 / (1024 * 1024) AS [GB],
       (8 * 1024 * SUM(s.reserved_page_count)) / (MAX(s.row_count)) AS [Bytes/Row]
FROM sys.dm_db_partition_stats s
    JOIN sys.objects o
        ON o.object_id = s.object_id
    JOIN sys.schemas sm
        ON sm.schema_id = o.schema_id
GROUP BY CONCAT('[', sm.name, '].[', o.name, ']')
HAVING MAX(s.row_count) > 0
ORDER BY GB DESC