2016-04-27 13 views
2

私は共有ポイントのBLOBストレージを実装しています。下のコードはうまくいきますが、ブロブのドライブ上のファイルストリームもカウントしていることを確認します。SQL - データベースのサイズを取得

SELECT [Database Name] = DB_NAME(database_id), 
     [Type] = CASE WHEN Type_Desc = 'ROWS' THEN 'Data File(s)' 
        WHEN Type_Desc = 'LOG' THEN 'Log File(s)' 
        ELSE Type_Desc END, 
     [Size in MB] = CAST(((SUM(Size)* 8)/1024.0) AS DECIMAL(18,2)) 
FROM sys.master_files 
-- Uncomment if you need to query for a particular database 
-- WHERE  database_id = DB_ID(‘Database Name’) 
GROUP BY  GROUPING SETS 
       (
        (DB_NAME(database_id), Type_Desc), 
        (DB_NAME(database_id)) 
      ) 
ORDER BY  DB_NAME(database_id), Type_Desc DESC 
GO 

答えて

0

これらのSQLスクリプトのいずれかを試してください。

SELECT 
    t.NAME AS TableName, 
    p.rows AS RowCounts, 
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB 
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 


--- SQL2005 
select o.name 
, reservedpages = sum(a.total_pages) 
, usedpages = sum(a.used_pages) 
, pages = sum(case when a.type <> 1 then a.used_pages 
when p.index_id < 2 then a.data_pages else 0 end) 
, SUM(a.used_pages)*8096 AS 'Size(B)' 
, rows = sum(case when (p.index_id < 2) and (a.type = 1) then p.rows else 0 end) 
from sys.objects o 
join sys.partitions p on p.object_id = o.object_id 
join sys.allocation_units a on p.partition_id = a.container_id 
where o.type = 'U' 
group by o.name 
order by 3 desc --biggest tables first 

さらに、いくつかのアイデアを提供するリンクがいくつかあります。

http://ask.sqlservercentral.com/questions/88859/sql-server-2008-r2-table-sizes.html

http://www.sqlmatters.com/Articles/Listing%20all%20tables%20in%20a%20database%20and%20their%20row%20counts%20and%20sizes.aspx

+0

ありがとうryguy7272。私はスクリプトをテストし、あなたに知らせるでしょう。それは有り難いです。 –

関連する問題