Javatpoint Logo
Javatpoint Logo

MySQL Show/List Tables

The show or list table is very important when we have many databases that contain various tables. Sometimes the table names are the same in many databases; in that case, this query is very useful. We can get the number of table information of a database using the following statement:

The following steps are necessary to get the list of tables:

Step 1: Open the MySQL Command Line Client that appeared with a mysql> prompt. Next, log in to the MySQL database server using the password that you have created during the installation of MySQL. Now, you are connected to the MySQL server, where you can execute all the SQL statements.

Step 2: Next, choose the specific database by using the command below:

Step 3: Finally, execute the SHOW TABLES command.

Let us understand it with the example given below. Suppose we have a database name "mystudentdb" that contains many tables. Then execute the below statement to list the table it contains:

The following output explains it more clearly:

MySQL Show/List Tables

We can also use the FULL modifier with the SHOW TABLES query to get the type of table (Base or View) that appears in a second output column.

This statement will give the following output:

MySQL Show/List Tables

If we want to show or list the table name from different databases or database to which you are not connected without switching, MySQL allows us to use the FROM or IN clause followed by the database name. The following statement explains it more clearly:

The above statement can also be written as:

When we execute the below statements, we will get the same result:

Output:

MySQL Show/List Tables

Show Tables Using Pattern Matching

Show Tables command in MySQL also provides an option that allows us to filter the returned table using different pattern matching with LIKE and WHERE clause.

Syntax

The following are the syntax to use pattern matching with show table command:

We can understand it with the example given below where percent (%) sign assumes zero, one, or multiple characters:

The above statement will give the following output:

MySQL Show/List Tables

Let us see another statement that returned the table names starting with "time":

The above query will give the following output:

MySQL Show/List Tables

Now, we are going to see how we can use the WHERE clause with the SHOW TABLES command to list different types of tables (either Base or View type) in the selected database:

This statement gives the below output:

MySQL Show/List Tables

It is noted that if MySQL does not provide the privileges for accessing a Base table or view, then we cannot get the tables in the result set of the SHOW TABLES command.

Here, we can also see another example of Show Tables statement with the WHERE clause:

It will give the following output:

MySQL Show/List Tables
Next TopicMySQL Rename Table





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA