To get the total number of rows in a MySQL database, you can use aggregate function SUM() along with inbuilt column TABLE_ROWS from INFORMATION_SCHEMA.TABLES.
The syntax is as follows−
SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();
假设我们正在使用名为’sample’的数据库。
现在我们将获取MySQL数据库中的总行数−
mysql> SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();
这将产生以下输出−
+-----------------+ | SUM(TABLE_ROWS) | +-----------------+ | 2043 | +-----------------+ 1 row in set (22.11 sec)原文来自:www.php.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容