Home  >  Article  >  Database  >  How to know the exact number of tables and columns in a MySQL database?

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

WBOY
WBOYforward
2023-09-09 22:13:02591browse

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

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

Suppose we have a database called "sample" and we need to operate on it to get the exact number of tables and columns.

To achieve this, 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';

Below is the output showing the number of tables and columns in the database ‘sample’ −

+------------+-------------+
| TotalTable | TOTALColumn |
+------------+-------------+
|        123 |         287 |
+------------+-------------+
1 row in set (0.02 sec)

The above is the detailed content of How to know the exact number of tables and columns in a MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete