我可以使用T-SQL向我显示表用于存储行的8K页数吗?
另外,我可以看到数据库正在使用的8K页数吗?
答案 0 :(得分:20)
尝试这样的事情:
-- 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
它显示了表格使用的页面 - 已使用,未使用和总计。
对于整个数据库 - 只需总结每个表的页面并重复每个数据库。
答案 1 :(得分:1)
从SQLSERVER2012开始显示行数的另一种方式..我搜索一些问题引导我到这里,我用我使用的那个更新了答案
select
object_name(object_id) as 'tablename',
count(*) as 'totalpages',
sum(Case when is_allocated=0 then 1 else 0 end) as 'unusedPages',
sum(Case when is_allocated=1 then 1 else 0 end) as 'usedPages'
from sys.dm_db_database_page_allocations(db_id(),null,null,null,'DETAILED')
group by
object_name(object_id)