Show Tables - (MySQL Tables & Views)
When working with a MySQL database, you might need to check what tables or views exist in a specific database. In this tutorial, we'll show you how to use the "SHOW TABLES" command to do just that.
Syntax
To show a list of tables in a MySQL database, you can use the following syntax:
SHOW TABLES [FROM database_name];
Where "database_name" is the name of the database you want to display the list of tables from. If you omit the "FROM database_name" part, MySQL will use the default database.
Example
Let's assume we have a database called "example_db" that contains three tables: "users", "orders", and "products". Here's how we can use the "SHOW TABLES" command to display a list of these tables:
SHOW TABLES FROM example_db;
Output
When we run the example code above, the output will be:
+----------------+
| Tables_in_example_db |
+----------------+
| orders |
| products |
| users |
+----------------+
3 rows in set (0.00 sec)
Explanation
In the example above, we used the "SHOW TABLES" command to display a list of tables in the "example_db" database. We specified the database using the "FROM database_name" clause.
The output shows a table with a single column containing the name of each table in the database.
Use
The "SHOW TABLES" command is useful when you need to check what tables or views exist in a specific database. You can also use it to verify that your database schema changes have been applied correctly.
Important Points
- The "SHOW TABLES" command is used to display a list of tables in a MySQL database.
- You can specify the database you want to display the list of tables from using the "FROM database_name" clause.
- The output is a table with a single column containing the name of each table in the specified database.
- If the database name is omitted, MySQL will use the default database.
Summary
In this tutorial, we showed you how to use the "SHOW TABLES" command to display a list of tables in a MySQL database. We covered the syntax, example, output, explanation, use, and important points of this command. With this knowledge, you can now easily check what tables exist in your MySQL databases.