
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to find the number of columns in a MySQL table?
- Get the number of columns in a MySQL table?
- How to alter the database engine of a MySQL database table?
- How to select the table with the greatest number of columns in MySQL?
- Exact count of all rows in MySQL database?
- Count the number of columns in a MySQL table with Java
- How to update two columns in a MySQL database?
- How to get the datatype of MySQL table columns?
- How to count the number of tables in a MySQL database?
- Counting the number of non-null or nonzero columns in a MySQL table?
- How to take backup of a single table in a MySQL database?
- How to check table status of the tables in a particular MySQL database?
- How to get the number of columns of a table using JDBC?
- How to count number of columns in a table with jQuery
- How to know the exact time to load a page using Selenium WebDriver?

Advertisements