Home >Database >Mysql Tutorial >How Can I Efficiently Determine Record Counts Across Multiple MySQL Database Tables?
Efficiently Counting Records Across Multiple MySQL Tables
Counting rows across numerous MySQL database tables can be time-consuming. This article offers a streamlined approach.
The following SQL query provides a total row count for all tables within a given database, avoiding individual SELECT COUNT(*)
queries for each table:
<code class="language-sql">SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{your_db}';</code>
It's important to acknowledge a key limitation. For InnoDB tables, the TABLE_ROWS
value is an estimate used for query optimization, not a precise count. To obtain exact counts, using COUNT(*)
remains necessary, although this method is computationally more expensive.
The above is the detailed content of How Can I Efficiently Determine Record Counts Across Multiple MySQL Database Tables?. For more information, please follow other related articles on the PHP Chinese website!