2011-05-18 74 views
6

它很容易檢查表和索引的存儲大小,你可以右鍵單擊SSMS瀏覽器上的表對象,瞧,細節出現在一個不錯的彈出窗口。如何檢查SQL Server中索引視圖的大小?

但由於索引視圖與普通視圖顯示相同,所以在SSMS中沒有可用的存儲信息來顯示磁盤上佔用的當前大小。

enter image description here

是否有alterate的方法來計算的尺寸(通過系統SP或類似的方法說)?

謝謝。

回答

13
EXEC sys.sp_spaceused @objname = N'dbo.YourView' 
+0

感謝馬丁,工作一種享受。 – 2011-05-18 18:19:52

3

您可以使用此查詢這裏找到你的數據對於任何給定的索引視圖:

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