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

数据库计算每个表所占空间和记录数

时间:2016-02-15 14:43:05      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

sql server

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

 

Mysql

/*这里面的单位是Byte*/
SELECT
    TABLE_NAME,
    DATA_LENGTH,
    INDEX_LENGTH,
    DATA_LENGTH + INDEX_LENGTH,
    TABLE_ROWS
FROM
    information_schema. TABLES
WHERE
    TABLE_SCHEMA = ‘database_20160215;

 

Oracle

/*查某一用户下的表*/
select SEGMENT_NAME, TABLESPACE_NAME, sum(BYTES) ||  Bytes
  from USER_extents
 where SEGMENT_TYPE = TABLE
 group by SEGMENT_NAME,
          TABLESPACE_NAME

/*查所有的表*/
select SEGMENT_NAME, TABLESPACE_NAME, sum(BYTES) ||  Bytes
  from dba_extents
 where SEGMENT_TYPE = TABLE
 group by SEGMENT_NAME, TABLESPACE_NAME

 

数据库计算每个表所占空间和记录数

标签:

原文地址:http://www.cnblogs.com/mtsl/p/5190378.html

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