sql查询数据库中所有表的记录条数,以及占用磁盘空间大小。

 1 SELECT
 2 TableName = obj.name,
 3 TotalRows = prt.rows,
 4 [SpaceUsed(KB)] = SUM(alloc.used_pages)*8
 5 FROM sys.objects obj
 6 JOIN sys.indexes idx on obj.object_id = idx.object_id
 7 JOIN sys.partitions prt on obj.object_id = prt.object_id
 8 JOIN sys.allocation_units alloc on alloc.container_id = prt.partition_id
 9 WHERE
10 obj.type = 'U' AND idx.index_id IN (0, 1)
11 GROUP BY obj.name, prt.rows
12 ORDER BY TotalRows DESC

 

posted @ 2015-11-27 15:10  ChineseMoonGod  阅读(5496)  评论(0编辑  收藏  举报