How to Show/List Tables in MySQL Database
Last Updated :
11 Jun, 2024
In MySQL, the SHOW TABLES
command is a powerful tool used to list the tables within a specific database. This command provides a convenient way to view the tables that exist in a database without needing to query the database schema directly.
In this article, we are going to explore various ways where we can show tables and list down in multiple ways to modify tables on user requirements and so on.
How to Show All Tables List in a MySQL Database
In MySQL, The SHOW TABLES
command is used to list the tables in a specific database. It provides a simple way to see the tables that exist within a database without having to query the database schema directly. The command returns a result set containing the names of all tables in the selected database. This is particularly useful when managing databases with multiple tables, as it allows us to quickly view the available tables and their names.
Syntax:
SHOW TABLES;
MySQL returns the results in a table with one column — Tables_in_DatabaseName. The tables are ordered in alphabetical order. The summary line tells us how many rows (or tables) are there in the database.
Steps to Get the List of Tables
Given below are the necessary steps to get the list of tables:
- Step 1: Open the MySQL Command Line or MSI installer. Now Log in to the MySQL database server with the help of a password. Now, we are connected to the MySQL server, where we can execute all the SQL statements.
- Step 2: Next, choose the required database by using the following command:
USE DATABASE_NAME;
- Step 3: Finally, execute the SHOW TABLES command.
Let us understand this with an example. Suppose, we have a database name "northwind" that contains many tables. Now run the following statement to list the tables it includes:
USE northwind;
SHOW TABLES;
Output:
Tables in databaseThe query first selects the "northwind" database as the current database and then lists all the tables in that database.
SHOW FULL TABLES Statement
The SHOW TABLES command allows us to show a table that is either a base table or a view. To also include the table type in the result, we can use the following command:
SHOW FULL TABLES;
Output:
Full TableIf we want to show or list the table name from different databases or databases to which we are not connected without switching then, MySQL allows us to use the FROM or IN clause followed by the database name. The following statement explains it more clearly:
SHOW TABLES FROM northwind;
OR,
SHOW TABLES IN northwind;
Output:
Using IN commandShow Tables Using Pattern Matching
There might be huge databases stored on our server. For a database that has many tables, listing all tables at a time may not be intuitive. In such situations, we can use the LIKE expression with MySQL's SHOW TABLES command to filter the list and only display tables that match a specific pattern.
The SHOW TABLES command in MySQL allows us to filter the displayed tables using patterns with the LIKE and WHERE clauses.
SHOW TABLES LIKE pattern;
OR,
SHOW TABLES WHERE expression;
Example 1: Using LIKE Pattern
Suppose, we want the statement to return only the names of those databases that begin with the letter 'C'. The query will look as follows:
SHOW TABLES LIKE 'C%';
Output:
Using "C%"Let us see another statement that returned the table names starting with "Ord%", where the percent (%) sign assumes zero, one, or multiple characters:
SHOW TABLES LIKE 'Ord%';
Output:
Using "Ord%"Example 2: Using the WHERE clause
This statement explains using the WHERE clause in the SHOW TABLES statement to list all the views in the northwind database.
SHOW TABLES FROM northwind WHERE Table_type= "BASE TABLE";
Output:
using WHERE clauseIf MySQL doesn't allow access to a base table or view, then those tables won't appear in the result when using the SHOW TABLES command.
Here, we can also see another example of a Show Tables statement with the WHERE clause:
SHOW TABLES In northwind WHERE Tables_in_northwind = "Customer";
Output:
Table recordsConclusion
Overall, We can use the SHOW TABLE statement to list all tables in a database. Using the SHOW FULL TABLE statement to return an additional column that indicates the object is a view or table. We can also show SHOW TABLE FROM statement to list tables in a database. Lastly, use the SHOW TABLE WHERE statement or SHOW TABLE LIKE statement to filter the tables in a database.
Similar Reads
How to Show Schema of a Table in MySQL Database?
A table schema in MySQL database defines the structure of table, including columns, data types, relationships between columns, etc. It is a blueprint for the table, describing how data is organized in the table and how it relates to other tables in the database. To see the schema of a table in MySQL
2 min read
How to Show a List of All Databases in MySQL
MySQL is a popular open-source relational database management system (RDBMS) that is uniquely used to construct expandable and high-productivity databases. MySQL, which was created by MySQL AB and later acquired by its current owner Oracle Corporation, was originally introduced in 1995. MySQL is rep
7 min read
How to Show a List of Databases in PL/SQL?
Managing databases is a fundamental aspect of database administration and development. In Oracle Database, schemas represent logical containers for database objects like tables, views, procedures, and functions. PL/SQL is the procedural extension of and used in Oracle Database and provides powerful
5 min read
How to Show Database in PL/SQL
PL/SQL is the Procedural Language/Structured Query Language and serves as a procedural language built-in extension to SQL language, which allows seamless integration of procedural constructs with SQL. One of the most common functions of a DBMS is the retrieval of information about databases which is
4 min read
How to list the Tables in a SQLite Database File ?
SQLite is a database engine which is written in C programming language. SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is
4 min read
How to List All Tables in a Schema in Oracle Database?
In Oracle Database, listing all tables within a schema can be crucial for database management and analysis. we can use specific queries to retrieve information about tables in our schema. Below, we explore various queries to list tables, focusing on the SYSOBJECTS view that provides essential metada
3 min read
How to count rows in MySQL table in PHP ?
PHP stands for hypertext preprocessor. MySQL is a database query language used to manage databases. In this article, we are going to discuss how to get the count of rows in a particular table present in the database using PHP and MySQL. Requirements: XAMPP Approach: By using PHP and MySQL, one can p
3 min read
How to Show All Tables in MySQL using Python?
A connector is employed when we have to use mysql with other programming languages. The work of mysql-connector is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server. In order to make python interact with
1 min read
How to List All Tables in Oracle?
In this article, we will discuss all the methods to list all tables in the oracle SQL Database. We have three types of a subset of tables available to use as identifiers which in turn help us to sort the required table names. Here, are the following types of table identifiers in the Oracle SQL Datab
2 min read
How to Get Database Size in SQL
SQL database size is important for effective management. It indicates the storage space occupied by tables, indexes, and other components. Knowing the size of a database is useful for various purposes, such as monitoring the growth, estimating the backup time, planning the storage capacity, and opti
7 min read