mysql和oracle查询表占用空间

mysql

需要先进入information_schema

select 
table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
WHERE table_schema='ln_hbpz'
order by data_length desc, index_length desc;

select table_name , (data_length/1024/1024) as data_mb , (index_length/1024/1024)   
as index_mb, ((data_length+index_length)/1024/1024) as all_mb, table_rows   
from information_schema.tables where table_schema = 'test' order by all_mb desc; 

table_name    --表名
data_mb       --数据容量
index_mb      --索引容量
all_mb        --总容量
table_rows    --条数
information_schema.tables --在这个库information_schema中的tables中查询
test --库名

oracle

SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
       D.TOT_GROOTTE_MB "表空间大小(M)",
       D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
       TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,
                     2),
               '990.99') "使用比",
       F.TOTAL_BYTES "空闲空间(M)",
       F.MAX_BYTES "最大块(M)"
  FROM (SELECT TABLESPACE_NAME,
               ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
               ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
          FROM SYS.DBA_FREE_SPACE 
         GROUP BY TABLESPACE_NAME) F,
       (SELECT DD.TABLESPACE_NAME,
               ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
          FROM SYS.DBA_DATA_FILES DD
         GROUP BY DD.TABLESPACE_NAME) D
 WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
/* and F.TABLESPACE_NAME = 'D_test_01'*/
 ORDER BY 4 DESC;

 

你可能感兴趣的:(mysql,oracle)