Skip to content

Instantly share code, notes, and snippets.

@NeilRobbins
Created March 22, 2012 13:58
Show Gist options
  • Save NeilRobbins/2158493 to your computer and use it in GitHub Desktop.
Save NeilRobbins/2158493 to your computer and use it in GitHub Desktop.
Show how many rows of database objects are held in SQL Server buffer
SELECT
DB_NAME(osbd.database_id)AS [Database Name],
OBJECT_NAME(p.[object_id]) AS [ObjectName],
sum(osbd.row_count) AS [Count of Rows],
au.[type_desc] AS [Allocation Unit Type],
osbd.page_type
FROM sys.allocation_units au
inner join sys.dm_os_buffer_descriptors osbd on au.allocation_unit_id = osbd.allocation_unit_id
inner join sys.partitions p on au.container_id = p.hobt_id
WHERE p.[object_id] > 100
GROUP BY
p.[object_id],
osbd.page_type,
p.[index_id],
au.[type_desc],
DB_NAME(osbd.database_id)
ORDER BY
[Count of Rows] DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment