一张表占用多少内存?

iva*_*nmp 9 sql-server memory cache

有没有办法找出表在 SQL Server(2005 及更高版本)中占用了多少内存?

例如,假设我有一个包含 3000 万条记录的表。我想知道当前缓冲区缓存中有多少属于该表的页面,包括索引、数据和文本/图像页面

我找到了 Pinal Dave 的这个查询,但似乎这个查询只返回由索引分配的页面(无论是集群的还是非集群的)。

Rem*_*anu 8

with bd as (
    select count(*) as pages_in_memory, bd.allocation_unit_id
    from sys.dm_os_buffer_descriptors bd
    where bd.database_id = db_id()
    group by bd.allocation_unit_id)
select p.object_id,
    p.index_id,
    p.partition_number,
    bd.pages_in_memory,
    au.total_pages as pages_on_disk,
    au.type_desc
from bd 
join sys.allocation_units au 
    on au.allocation_unit_id = bd.allocation_unit_id
join sys.partitions p
    on p.partition_id = au.container_id
Run Code Online (Sandbox Code Playgroud)