zoukankan      html  css  js  c++  java
  • sql server性能分析查看表数据页数

    返回表名、索引名和行数
    SELECT object_name(i.object_id) as objectName, i.[name] as indexName, sum(p.rows) as rowCnt
    FROM sys.indexes i
    INNER JOIN sys.partitions p
    ON i.object_id = p.object_id
    AND i.index_id = p.index_id
    WHERE i.object_id = object_id('dbo.Meeting')
    AND i.index_id <= 1
    GROUP BY i.object_id, i.index_id, i.[name]

    返回表的总页数、使用页数、数据页数
    SELECT object_name(i.object_id) as objectName, i.[name] as indexName,
    sum(a.total_pages) as totalPages, sum(a.used_pages) as usedPages, sum(a.data_pages) as dataPages,
    (sum(a.total_pages) * 8) / 1024 as totalSpaceMB, (sum(a.used_pages) * 8) / 1024 as usedSpaceMB,
    (sum(a.data_pages) * 8) / 1024 as dataSpaceMB
    FROM sys.indexes i
    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 i.object_id = object_id('dbo.Meeting')
    AND i.index_id <= 1
    GROUP BY i.object_id, i.index_id, i.[name]

    按页类型分类统计
    SELECT case when grouping(i.object_id) = 1 then '--- TOTAL ---' else object_name(i.object_id) end as objectName,
    case when grouping(i.[name]) = 1 then '--- TOTAL ---' else i.[name] end as indexName,
    case when grouping(a.type_desc) = 1 then '--- TOTAL ---' else a.type_desc end as pageType,
    sum(a.total_pages) as totalPages, sum(a.used_pages) as usedPages, sum(a.data_pages) as dataPages,
    (sum(a.total_pages) * 8) / 1024 as totalSpaceMB, (sum(a.used_pages) * 8) / 1024 as usedSpaceMB, (sum(a.data_pages) * 8) / 1024 as dataSpaceMB
    FROM sys.indexes i
    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 i.object_id = object_id('dbo.Meeting')
    AND i.index_id <= 1
    GROUP BY i.object_id, i.[name], a.type_desc with rollup
  • 相关阅读:
    s2-032批量脚本
    javascript 1
    threading模块和queue模块实现程序并发功能和消息队列
    Python标准库06 子进程 (subprocess包)
    常用服务对应的正则
    re
    requests
    198. 打家劫舍
    746. 使用最小花费爬楼梯
    70. 爬楼梯
  • 原文地址:https://www.cnblogs.com/zping/p/1911406.html
Copyright © 2011-2022 走看看