查询sqlserver表占用空间,查询当前数据库缓存的所有数据页面,查询当前数据库经常访问的表

查询某张表的磁盘占用情况:

sql 复制代码
--第一种
EXEC sp_spaceused '表_测试表';



--第二种
SELECT 
    OBJECT_NAME(object_id) AS TableName,
    SUM(used_page_count) * 8 AS UsedSpaceKB
FROM 
    sys.dm_db_partition_stats
GROUP BY 
    object_id;

查询当前数据库缓存的所有数据页面,哪些数据表,缓存的数据页面数量 -- 从这些信息可以看出,系统经常要访问的都是哪些表,有多大?

sql 复制代码
select p.object_id, object_name=object_name(p.object_id), p.index_id, buffer_pages=count(*) from
 sys.allocation_units a, sys.dm_os_buffer_descriptors b, sys.partitions p where 
 a.allocation_unit_id=b.allocation_unit_id and a.container_id=p.hobt_id and b.database_id=db_id() group by p.object_id,p.index_id order by buffer_pages desc
相关推荐
龙仔7254 小时前
SQL Server 批量多库只读账号一键脚本(带逐行注释完整脚本 + 分段逐句详细解释)
服务器·数据库·sql·sqlserver·dba
xuefuhe5 天前
SQL Server查看系统存储过程及视图的定义
sqlserver
techdashen5 天前
Uber 如何完成超大规模 JUnit 迁移:从 JUnit 4 到 JUnit 5 的自动化工程实践
junit·sqlserver·自动化
xuefuhe7 天前
SQL Server Configuration Manager报Cannot connect to WMI provider错误
sqlserver
殳翰9 天前
spring对junit的支持
spring·junit·sqlserver
可触的未来,发芽的智生9 天前
发现-认知系统记忆架构工程启示录
数据库·人工智能·python·程序人生·sqlserver
ClouGence10 天前
SQL Server CDC 如何降低主库压力?Always On 备库读取实践
数据库·后端·sql·sqlserver
数据库小学妹1 个月前
SQL Server数据库同步工具怎么选?6款方案对比+信创迁移避坑清单
数据库·经验分享·sqlserver·dba
铁打的阿秀1 个月前
SQL server2025 Express安装及管理工具安装使用教程(Windows)
windows·sqlserver·express
文盲老顾1 个月前
sqlserver 根据IP和数量,计算应该使用的掩码IP地址段
sqlserver·递归·自定义函数·cte·ip掩码·表值函数