Skip to content

Instantly share code, notes, and snippets.

@ignas-sakalauskas
Last active March 27, 2017 17:40
Show Gist options
  • Save ignas-sakalauskas/795bf8ce997493199327e2905d9a8bbc to your computer and use it in GitHub Desktop.
Save ignas-sakalauskas/795bf8ce997493199327e2905d9a8bbc to your computer and use it in GitHub Desktop.
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