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

来自:网络
时间:2024-06-07
阅读:
免费资源网 - https://freexyz.cn/

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;

总结

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

免费资源网 - https://freexyz.cn/
返回顶部
顶部