SQL Server:表和/或数据库使用的 8K 页数 [英] SQL Server: Number of 8K Pages Used by a Table and/or Database

查看:21
本文介绍了SQL Server:表和/或数据库使用的 8K 页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 T-SQL 显示一个表用于存储其行的 8K 页的数量吗?

Can I use T-SQL to show me the number of 8K pages that a table is using to store its rows?

另外,我能看到一个数据库正在使用的 8K 页数吗?

Also, can I see the number of 8K pages that a database is using?

推荐答案

试试这个:

-- Total # of pages, used_pages, and data_pages for a given heap/clustered index
SELECT 
    t.NAME AS TableName,
    p.rows AS RowCounts,
    SUM(a.total_pages) AS TotalPages, 
    SUM(a.used_pages) AS UsedPages, 
    (SUM(a.total_pages) - SUM(a.used_pages)) AS UnusedPages
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, p.Rows
ORDER BY 
    t.Name

这会显示表格使用的页数 - 已使用、未使用和总计.

That shows you the pages used by the tables - used, unused and total.

对于整个数据库 - 只需总结每个表的页面并为每个数据库重复.

For the whole database - just sum up the pages for each table and repeat for each database .

这篇关于SQL Server:表和/或数据库使用的 8K 页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆