MySQL SHOW TABLES Statement: A Complete Guide

MySQL SHOW TABLES Statement: A Complete Guide

Estimated reading time: 2 minutes

The MySQL SHOW TABLES statement lists all tables in a database. This guide explains the syntax, options, and practical uses for SHOW TABLES, including how to filter results by table type and specific patterns.


Syntax

Parameters

  • FROM database_name: Specifies the database to view tables from. If omitted, MySQL will show tables from the currently selected database.
  • LIKE ‘pattern’: Filters the results to show only tables matching a specific pattern. Wildcards (e.g., % for multiple characters) are allowed.
  • WHERE expression: Uses an SQL expression to filter the results based on criteria like table names, types, and more.

Basic Usage

To view all tables in the currently selected database, simply use:

This command lists every table in the active database, including tables, views, and other table-like objects.

Example

Suppose you are connected to a database named company_db. To see all tables in company_db, execute:

This will return a list of all tables, as shown below:

This command lists all tables in the current database (company_db in this case).


Practical Examples

List Tables with a Specific Prefix

To view only tables with a specific prefix (e.g., all tables related to “employee”):

View Tables in Multiple Databases

Use SHOW TABLES with FROM to view tables across different databases without changing the active database:

View tables from specific database

Here, SHOW TABLES FROM sales_db lists tables specifically from the sales_db database.

Using SHOW FULL TABLES; to View Table Types

The SHOW FULL TABLES; command adds a Table_type column, showing if each item is a BASE TABLE or a VIEW.

SHOW FULL TABLES with Filtering by Table Type

Using WHERE Table_type = 'VIEW' filters the results to show only views in the database.

Filtering with WHERE Clause for Partial Matches

This command lists tables that contain “dept” in their names.


  1. MySQL SHOW TABLES Documentation
  2. MySQL Full-Text Searches
  3. MySQL WHERE Clause Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *