码迷,mamicode.com
首页 > 数据库 > 详细

Get size of all tables in database

时间:2014-08-16 00:57:29      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   art   div   

http://stackoverflow.com/questions/7892334/get-size-of-all-tables-in-database

SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    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
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE dt% 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    t.Name

 

Get size of all tables in database,布布扣,bubuko.com

Get size of all tables in database

标签:style   blog   http   color   io   ar   art   div   

原文地址:http://www.cnblogs.com/yanyan45/p/3915863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!