Last active
March 27, 2017 17:40
-
-
Save ignas-sakalauskas/795bf8ce997493199327e2905d9a8bbc to your computer and use it in GitHub Desktop.
SQL database and tables sizes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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