当前位置: 代码网 > it编程>数据库>Mysql > mysql中如何查询多个表中的数据量

mysql中如何查询多个表中的数据量

2024年05月27日 Mysql 我要评论
mysql查询多个表的数据量查询多个表中的数据量,有两种方式进行查询。selecttable_schema as '数据库' ,table_name as '表名' ,table_rows as '

mysql查询多个表的数据量

查询多个表中的数据量,有两种方式进行查询。

select
table_schema as '数据库'  ,
table_name as '表名' ,
table_rows as '记录数量'
from information_schema.tables
where table_schema = 'nfds' 
and table_name in 
(
'name1' ,
'name2' ,
'name3'
)

另外的一个方式是

select count(*) from name1
union select count(*) from name2
union select count(*) from name3

这两种方式的话是有一点不同,后面一种的话是能记录数据库中所有的数据,前一种的话是不会主动更新相关的记录,在很多情况下会让数据库中数据少。

use [test] -- 只需修改这里的库名

select  a.name table_name, -- 表名
        a.crdate crdate, -- 建表时间
        b.rows rows, -- 总行数
        8*b.reserved/1024 reserved, -- 保留大小(mb)
        rtrim(8*b.dpages/1024) used, -- 已使用大小(mb)
        8*(b.reserved-b.dpages)/1024 unused -- 未使用大小(mb)
from    sysobjects as a
        inner join sysindexes as b on a.id = b.id
where   ( a.type = 'u' )
        and ( b.indid in ( 0, 1 ) )
order by a.name,b.rows desc;

mysql查询数据量最大的表

select table_name,table_rows from information_schema.tables where table_schema = “数据库名” order by table_rows desc limit 10;

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com