MYSQL - 计算每个表中的行数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4603272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MYSQL - count number of rows in each table
提问by Redconnection
I would like to know how many rows are in each table in my database. I've come so far as to having
我想知道我的数据库中每个表中有多少行。我已经做到了
select count(*) _tablename_;
However i would need to do that on each and every table - and there are a lot. What would me the best way to get a print-out with the table name and it's row count?
但是,我需要在每张桌子上都这样做 - 而且有很多。我用表名和行数打印输出的最佳方法是什么?
回答by moinudin
SELECT table_name, table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<your db>';
I also hope you realise there's an error in your query: it's missing a FROM
.
我也希望您意识到您的查询中有一个错误:它缺少一个FROM
.
回答by Sarita Ishwarkar
This following query will return number of rows in each table but it doesn't seem to return exact value all the time
以下查询将返回每个表中的行数,但它似乎并不总是返回精确值
SELECT table_name, table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<your db>';
TABLE_ROWS: The number of table rows in the partition. For partitioned InnoDB tables, the row count given in the TABLE_ROWS column is only an estimated value used in SQL optimization, and may not always be exact... for more https://dev.mysql.com/doc/mysql-infoschema-excerpt/5.5/en/partitions-table.html
TABLE_ROWS:分区中的表行数。对于分区的 InnoDB 表,TABLE_ROWS 列中给出的行数只是 SQL 优化中使用的估计值,可能并不总是准确的...更多https://dev.mysql.com/doc/mysql-infoschema-摘录/5.5/en/partitions-table.html
回答by Eddie Kumar
In addition to SQL queries by others, one can also use Workbench GUI to get the row-counts of each table. To do this, Launch Workbench -> Connect to Db -> right click Db and select "Schema Inspector" (as in Screenshot below - I have highlighted the "Rows" column):
除了其他人的 SQL 查询外,还可以使用 Workbench GUI 来获取每个表的行数。为此,启动 Workbench -> 连接到 Db -> 右键单击 Db 并选择“架构检查器”(如下面的屏幕截图所示 - 我已突出显示“行”列):
HTH.
哈。