Apply MySQL query to each table in a database?

MySQLMySQLi Database

To apply MySQL query to each table in a database, you can use INFORMATION_SCHEMA.TABLES. Following is the syntax −

SELECT SUM(TABLE_ROWS) AS anyAliasName
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA=yourDatabaseName;

Let us implement the above syntax to query each table in a database.

mysql> SELECT SUM(TABLE_ROWS) AS Total
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA= DATABASE();

This will produce the Following output −

+-------+
| Total |
+-------+
| 1666  |
+-------+
1 row in set (0.01 sec)
raja
Published on 29-Apr-2019 12:11:56
Advertisements