Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-09-09 22:13:02
forward
612 people have browsed it

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';
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!