Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SQL database and tables sizes
-- Database size in MB
SELECT
SUM(reserved_page_count) * 8.0 / 1024 AS 'MB'
FROM sys.dm_db_partition_stats
-- https://ignas.me/tech/sql-database-tables-sizes/
-- Database table sizes in MB
SELECT
sys.objects.name,
SUM(reserved_page_count) * 8.0 / 1024 AS 'MB'
FROM sys.dm_db_partition_stats,
sys.objects
WHERE sys.dm_db_partition_stats.object_id = sys.objects.object_id
-- Line below limits query to return user created tables only
AND sys.objects.type_desc = 'USER_TABLE'
GROUP BY sys.objects.name
ORDER BY MB DESC
-- https://ignas.me/tech/sql-database-tables-sizes/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.