如何检查 SQL Server 中索引视图的大小?

发布于 2024-11-08 21:12:40 字数 248 浏览 0 评论 0原文

检查表和索引的存储大小很容易,您可以右键单击 SSMS 资源管理器上的表对象,瞧,详细信息会显示在一个漂亮的弹出窗口中。

但由于索引视图的显示方式与普通视图相同,因此 SSMS 中没有可用的存储信息来显示磁盘上当前占用的大小。

在此处输入图像描述

是否有其他方法来计算大小(例如通过系统 SP 或类似方法)?

谢谢。

Its easy to check storage sizes for Tables and Indexes, you can right-click the table object on SSMS explorer and voila, the details appear in a nice popup.

But since Indexed Views are displayed the same as Normal Views, there is no storage information avaiable in SSMS to show me the current size taken up on disk.

enter image description here

Is there an alterate way to calculate the size (say via a system SP or similar method)?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆离笙 2024-11-15 21:12:41
EXEC sys.sp_spaceused @objname = N'dbo.YourView'
EXEC sys.sp_spaceused @objname = N'dbo.YourView'
星軌x 2024-11-15 21:12:41

您可以在此处使用此查询来查找任何给定索引视图的数据:

SELECT 
    v.NAME AS ViewName,
    i.name AS IndexName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    SUM(a.data_pages) * 8 AS DataSpaceKB
FROM 
    sys.views v
INNER JOIN      
    sys.indexes i ON v.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 
    v.Name = 'YourViewNameHere' --View name only, not 'schema.viewname'
    AND
    i.index_id = 1   -- clustered index, remove this to see all indexes
GROUP BY 
    v.NAME, i.object_id, i.index_id, i.name, p.Rows

给出类似的输出

ViewName      IndexName     RowCounts  TotalSpaceKB  UsedSpaceKB  DataSpaceKB
YourViewName  IX_YourView     1771         592           552          536

You can use this query here to find your data for any given indexed view:

SELECT 
    v.NAME AS ViewName,
    i.name AS IndexName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    SUM(a.data_pages) * 8 AS DataSpaceKB
FROM 
    sys.views v
INNER JOIN      
    sys.indexes i ON v.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 
    v.Name = 'YourViewNameHere' --View name only, not 'schema.viewname'
    AND
    i.index_id = 1   -- clustered index, remove this to see all indexes
GROUP BY 
    v.NAME, i.object_id, i.index_id, i.name, p.Rows

Gives an output something like

ViewName      IndexName     RowCounts  TotalSpaceKB  UsedSpaceKB  DataSpaceKB
YourViewName  IX_YourView     1771         592           552          536
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文