mysql怎么查询表的行数

来源:这里教程网 时间:2026-02-28 14:56:47 作者:

本教程操作环境:windows7系统、mysql8版本、Dell G3电脑。

mysql查询表的行数

1.获取单表的行数

SELECT 
    COUNT(*)
FROM
    table_name;

2.获取多表的行数(可以使用UNION运算符组合每个SELECT语句返回的结果集)

SELECT 
    'tablename1' tablename, 
     COUNT(*) rows
FROM
    table_name1UNION SELECT 
    'tablename2' tablename, 
     COUNT(*) rows
FROM
    table_name2;

3.获取某个数据库的所有表的行数(information_schema 方法有时候不准确)

use information_schema;
select table_name,table_rows from tables 
where TABLE_SCHEMA = 'db.name' 
order by table_rows desc;

【相关推荐:mysql视频教程】

相关推荐