MySQL SHOW TABLES Statement


MySQL SHOW TABLES Statement

The MySQL SHOW TABLES statement is used to list all the tables in the current database. This statement is essential for viewing the existing tables and confirming table creation.


Syntax

SHOW TABLES;

The SHOW TABLES statement does not have any optional clauses or parameters. It simply lists all tables available in the current database.


Example MySQL SHOW TABLES Statement

Let's look at an example of the MySQL SHOW TABLES statement and how to use it:

Step 1: Using the Database

USE mydatabase;

This query sets the context to the database named mydatabase.

MySQL USE DATABASE

Step 2: Creating Tables

Next, create some tables in the database:

CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    email VARCHAR(100) UNIQUE
);

CREATE TABLE departments (
    id INT AUTO_INCREMENT PRIMARY KEY,
    department_name VARCHAR(50) NOT NULL
);

This query creates two tables: employees and departments.

MySQL CREATE TABLE

Step 3: Listing All Tables

SHOW TABLES;

This query lists all tables in the current database. The result will be a list of all table names available in the database.

MySQL SHOW TABLES

Conclusion

The MySQL SHOW TABLES statement is a straightforward but powerful tool for listing all tables in the current database. Understanding how to use this statement is essential for database management and verification in MySQL.