mysql 查看某数据库中所有表的行数,information_schema.tables不准确。count(*)拼接准确。
mysql使用information_schema.tables统计表的行数,统计结果和count(*)的结果不一样。
select table_name,table_rows from information_schema.tables
where TABLE_SCHEMA = 'qyqdb'
order by table_rows desc;
经查询:information_schema.tables 对于InnoDB表,table_rows行计数仅是大概估计值,不准确。
mysql使用select count(*) from table_name可以查询某个表的总记录数。比较准确!
想快速的知道数据库中所有表的记录数信息怎么办?
另外一种办法还是借助information_schema库的tables表,来拼接出一个条sql语句,例如:
统计qyqdb数据库下所有的表的行数,生产统计语句。
select concat('select "', TABLE_name, '", count(*) from ', TABLE_SCHEMA, '.',TABLE_name,' union all'
) from information_schema.tables
where TABLE_SCHEMA='qyqdb';
把生成的结果手动加工一下。
举例如下:
统计bigData_1数据库下所有表的行数:
select concat('select "', TABLE_name, '", count(*) from ', TABLE_SCHEMA, '.',TABLE_name,' union all'
) from information_schema.tables
where TABLE_SCHEMA in ('bigData_1');结果:
+------------------------------------------------------------------------------------------------------------------------------------+
| concat('select "', TABLE_name, '", count(*) from ', TABLE_SCHEMA, '.',TABLE_name,' union all'
) |
+------------------------------------------------------------------------------------------------------------------------------------+
| select "AA_cert_action_day", count(*) from bigdata_1.AA_cert_action_day union all |
| select "AA_cert_action_month", count(*) from bigdata_1.AA_cert_action_month union all |
| select "AA_cert_day", count(*) from bigdata_1.AA_cert_day union all |
| select "AA_cert_month", count(*) from bigdata_1.AA_cert_month union all |
+------------------------------------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)mysql>
对以上输出结果进行修改,如下:
select "AA_cert_action_day", count(*) from bigdata_1.AA_cert_action_day union all
select "AA_cert_action_month", count(*) from bigdata_1.AA_cert_action_month union all
select "AA_cert_day", count(*) from bigdata_1.AA_cert_day union all
select "AA_cert_month", count(*) from bigdata_1.AA_cert_month输出结果如下:
mysql> select "AA_cert_action_day", count(*) from bigdata_1.AA_cert_action_day union all -> select "AA_cert_action_month", count(*) from bigdata_1.AA_cert_action_month union all-> select "AA_cert_day", count(*) from bigdata_1.AA_cert_day union all -> select "AA_cert_month", count(*) from bigdata_1.AA_cert_month-> ;
+--------------------------+----------+
| report_cert_action_day | count(*) |
+--------------------------+----------+
| AA_cert_action_day | 168 |
| AA_cert_action_month | 131 |
| AA_cert_day | 82 |
| AA_cert_month | 39 |
+--------------------------+----------+
4 rows in set (0.00 sec)mysql>
mysql 查看某数据库中所有表的行数,information_schema.tables不准确。count(*)拼接准确。相关推荐
- server sql 数据总行数_SqlServer中获取数据库中每个表的行数
CREATE TABLE #RowCounts(NumberOfRows BIGINT,TableName VARCHAR(128)) EXEC sp_MSForEachTable 'INSERT I ...
- 查询数据库中所有表的行数(sqlserver 2000)
方法一: create proc ss as set nocount on create table TableSpace ( TableName varchar(50), RowsCount c ...
- mysql查询一个数据库所有表的记录数,mysql 查看数据库中所有表的记录数
mysql使用select count(*) from table_name可以查询某个表的总记录数.想快速的知道数据库中所有表的记录数信息怎么办?如果使用mysql的版本在5.0及以上,可以通过查询 ...
- mysql查看当前库所有表记录数_mysql中查看数据库中所有表的记录数
我们继续我们的博客创建. 在一个项目日常的运行中,常常会为服务过慢而导致用户体验不好,在这一点上,常常需要进行性能优化,而如果没有针对性的对某一个 模块进行优化,那么效果往往是不理 ...
- java语言获取数据库中的表的总行数
java语言从数据库中获取表的总行数 #java语言从数据库中获取表的总行数 获取数据库表中的总行数,用于做分页查询的动态更新.在这里我也是迷了半天,下面给出代码,应该所有的查询行数的代码都是这种的格 ...
- 查询数据库中所有表的记录数
查询数据库中所有表的记录数 方法1 直接查询,方法简单,但达不到想要的效果,记录数稍微多一点,总数就偏高 方法2 拼接 select count(主键id) 语句 方法1 直接查询,方法简单,但达不到 ...
- mysql查看当前数据库中表明,MySQL中查看当前数据库的所有表
关键词 MySQL数据库 表 摘要 本文介绍在MySQL数据库中,如何列出并查看当前数据库的所有表. 本文介绍在MySQL数据库中,如何列出并查看当前数据库的所有表. 我们创建一个数据库之后,数据库里 ...
- 查看PostgreSQL数据库中所有表
作为曾经干过运维的我来说,或许对大部分运维人员来说,不能依靠管理工具来操作数据库,如pgAdmin,经常远程登录到某一台数据库服务器,使用命令行的方式查询数据库中的表. 获取当前db中所有的表信息. ...
- 数据库信息 (表名 行数 堆 集群 非聚集)的查询
/************************************************************ * Time: 2010-10-07 13:23:32 * 找出有索引的表信 ...
最新文章
- poj 2449 Remmarguts' Date 启发式搜索 A*算法
- 当年我见过最烂的上网行为审计产品
- nginx服务器带宽_Nginx限制带宽配置示例
- VHDL中的分辨函数
- python 图例颜色_python – 来自颜色字典的matplotlib.pyplot scatterplot图例
- java体系的中间件适用于go吗_golang gf框架自定义中间件实现管理界面授权
- 1400 序列分解(dfs)
- Python安装时0x80070642问题解决
- 卓越的社会化营销人的6个习惯
- 火狐浏览器不能看网页视频了的解决方法
- C 判断 —— switch语句(输入的年份判断是否为闰年,根据输入的月份判断这月有多少天)
- 定点补码加减法运算_定点加减法运算与溢出判断处理
- flutter ListView.separated 带分割线
- 使用Python实现消息轰炸
- F - Fairy, the treacherous mailman
- App logo图标或内部icon的动态替换
- StateFlow-自动变速逻辑搭建
- mac OS 命令行升级软件系统的命令
- 华中科技大学计算机大专毕业,#985变大专#华科大:本科不努力,毕业变专科 !...
- 计算机毕业设计SpringBoot选题推荐—校园在线拍卖系统
热门文章
- aix linux ftp,在AIX下安装配置FTP服务器
- 服务器安装lnmp的时候出现client_loop: send disconnect: Connection reset by peer
- idw matlab 程序_IDW 算法MATLAB 实现 -
- Hadoop(四)hdfs基本操作
- mysql搭建主从结点
- 万丰科技机器人排名_万丰科技拟“借壳”长春经开
- server sql 统计信息 过时_sql-server – 何时更新统计信息?
- unity Conditional特性 总结
- 如何从Microsoft SQL Server生成C#类
- ML.NET 9月更新