MySQL SHOW TABLES: List Tables in a MySQL Database
The SHOW TABLES statement in MySQL is used to display all tables in the currently selected database. This command is useful for verifying the existence of tables, debugging, or exploring a database structure.
Syntax
This command lists all tables in the currently selected database.
Example 1: Show All Tables in a Database
Before listing tables, ensure you have selected a database using the USE statement.
Output Example:
Example 2: Show Tables Matching a Pattern
To filter tables by a specific pattern, use the LIKE clause:
This command lists all tables that start with "emp".
Output Example:
Example 3: Show Tables with a WHERE Clause
Alternatively, you can use WHERE with the Table_type
column when used with INFORMATION_SCHEMA:
This query fetches table names specifically from the my_database schema.
Example 4: Show Temporary Tables
If you want to list only temporary tables, use:
This helps in identifying temporary tables that follow a specific naming convention.
Example 5: Show Tables from Another Database
Even if you're in a different database, you can check tables from another database using:
Permissions Required
To run SHOW TABLES, you need the SELECT privilege on the database. Without sufficient privileges, you may not see all tables.
Conclusion
- SHOW TABLES lists all tables in the currently selected database.
- Use LIKE or WHERE to filter table names.
- You need appropriate permissions to view tables.
Would you like additional details or examples on specific database queries? 🚀