Skip to content

PopSQL: limited support.

Migrate now →

Largest tables

Rows and reserved space per table, from partition stats.

SQL Server · SQL
SELECT TOP 25
       s.name + '.' + t.name AS table_name,
       SUM(CASE WHEN p.index_id IN (0, 1) THEN p.row_count ELSE 0 END) AS rows_count,
       SUM(p.reserved_page_count) * 8 / 1024 AS reserved_mb,
       SUM(p.used_page_count) * 8 / 1024 AS used_mb
FROM sys.dm_db_partition_stats p
JOIN sys.tables t ON t.object_id = p.object_id
JOIN sys.schemas s ON s.schema_id = t.schema_id
GROUP BY s.name, t.name
ORDER BY reserved_mb DESC

This query is part of the "SQL Server health" pack: connect the database in DataRunner and install the whole pack — queries, dashboard and checks — at once.