Created
February 5, 2018 14:10
-
-
Save umair-me/a7b93acba350a94b80fb7816d85c10ee to your computer and use it in GitHub Desktop.
List the MB of RAM used by each database
This file contains hidden or 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
SELECT | |
MemoryUsage.DatabaseName, | |
SUM(MBUsed) | |
FROM | |
( | |
SELECT DB_NAME(t.dbid) AS DatabaseName, SUM(size_in_bytes/(1024*1024)) AS MBUsed | |
FROM sys.dm_exec_cached_plans AS p | |
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t | |
WHERE t.dbid < 32767 | |
GROUP BY t.dbid | |
UNION ALL | |
SELECT DB_NAME(database_id), | |
COUNT (*) * 8 / 1024 AS MBUsed | |
FROM sys.dm_os_buffer_descriptors | |
GROUP BY database_id | |
) AS MemoryUsage | |
GROUP BY MemoryUsage.DatabaseName | |
ORDER BY SUM(MBUsed) DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment