本文介绍了mysql与oracle中取得表行数与表大小的方法,Mysql得到表行数、Mysql得到表大小、Mysql得到库的大小以及oracle得到表行数与表大小的例子,需要的朋友参考下。
本节内容:
mysqloracle数据库中取得表行数与表大小
一,Mysql得到表行数
复制代码 代码示例:
SELECT table_schema, table_name, table_rows
FROM information_schema.tables
ORDER BY table_rows DESC
或者:
SELECT table_schema, table_name, table_rows
FROM information_schema.tables
where table_schema='test'
ORDER BY table_rows DESC
二,Mysql得到表大小:
复制代码 代码示例:
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 3) "MB"
FROM information_schema.TABLES
WHERE table_schema = "test"
ORDER BY (data_length + index_length) DESC;
三,Mysql得到库的大小:
复制代码 代码示例:
SELECT table_schema "DB Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema
order by sum(data_length + index_length) DESC;
上面的SQL在Mysql 5.6.14上面测试通过(www.jb200.com 编辑整理)。
四,Oracle怎么得到表的总行数及大小.
1)、Oracle得到表的总行数
Sys用户可以这样:
复制代码 代码示例:
select table_name, num_rows counter
from dba_tables
where owner = 'TMD'
order by num_rows desc
nulls last;
普通用户:
复制代码 代码示例:
select table_name, num_rows counter
from all_tables
where owner = 'TMD'
order by num_rows desc
nulls last;
或者:
复制代码 代码示例:
select table_name, num_rows counter
from user_tables
order by num_rows desc
nulls last;
2)、如果想得到一个文本汇总文件,可以写脚本:
复制代码 代码示例:
set pages 999;
col count format 999,999,999;
spool f:/saveFile/tmp/countlist.txt
select
table_name,
to_number(
extractvalue(
xmltype(
dbms_xmlgen.getxml('select count(*) c from '||table_name))
,'/ROWSET/ROW/C')) count
from
user_tables
order by
table_name;
spool off;
3)、oracle中获取表的大小的方法。
sys用户:
复制代码 代码示例:
select segment_name,segment_type,bytes/1024/1024 MB
from dba_segments
where segment_type='TABLE' and OWNER = 'TMD'
order by bytes desc;
普通用户,可以这样:
复制代码 代码示例:
select segment_name table_name, sum(bytes) / (1024 * 1024) table_size_meg
from user_extents
where segment_type = 'TABLE'
group by segment_name;
以上代码在oracle 10g测试通过。