How to know the exact number of table and columns in a MySQL 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)

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

172 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements