How to know the exact number of table and columns in a MySQL database?

MySQLMySQLi Database

To get the exact number if table and columns in a MySQL database, use the DISTINCT inside COUNT().

Let’s say we have a database ‘sample’ and we need to work on it to get the exact number of table and columns.

To achieve it, the query is as follows −

mysql> SELECT COUNT(DISTINCT TABLE_NAME) AS TotalTable,Count(Column_Name) AS TOTALColumn
   -> FROM INFORMATION_SCHEMA.COLUMNS
   -> WHERE TABLE_SCHEMA = 'sample';

The following is the output displaying the count of table and columns in the database ‘sample’ −

+------------+-------------+
| TotalTable | TOTALColumn |
+------------+-------------+
|        123 |         287 |
+------------+-------------+
1 row in set (0.02 sec)
raja
Published on 19-Mar-2019 08:14:07
Advertisements