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;
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论