查询某张表的磁盘占用情况:
--第一种
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;
查询当前数据库缓存的所有数据页面,哪些数据表,缓存的数据页面数量 – 从这些信息可以看出,系统经常要访问的都是哪些表,有多大?
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