Home > Database > Mysql Tutorial > body text

Can we get the total row count of MySQL database?

WBOY
Release: 2023-09-13 17:37:07
forward
1330 people have browsed it

我们可以获得 MySQL 数据库的总行数吗?

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();
Copy after login

Suppose we are using a database named 'sample'.

Now we will get the total number of rows in the MySQL database−

mysql> SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = database();
Copy after login

This will produce the following output−

+-----------------+
| SUM(TABLE_ROWS) |
+-----------------+
| 2043            |
+-----------------+
1 row in set (22.11 sec)
Copy after login

The above is the detailed content of Can we get the total row count of MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!