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: Show
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: 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: 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: Show Tables Using Pattern MatchingShow 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: Let us see another statement that returned the table names starting with "time": The above query will give the following output: 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: 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. This Engineering Education (EngEd) Program is supported by Section. Instantly deploy containers across multiple cloud providers all around the globe. Try It For Free Visual Database Design with MySQL Workbench January 18, 2021MySQL Workbench is a graphical visual database design tool with multiple functionalities. This tutorial will cover database design and modeling with MySQL Workbench. PrerequisitesThis article is suitable for beginner to intermediate MySQL Workbench users. It requires no prior knowledge of MySQL Workbench. However, knowledge in relational databases and database design may be required. To get started with the MySQL database, check the MySQL Tutorial website. Introduction to MySQL WorkbenchThere are two editions of MySQL Workbench: the community edition and the commercial edition. The community edition is open source. Both editions are available for three major platforms; MS Windows, macOS, and Linux. The commercial edition comes with more functionalities at a cost. Some of the extra functionalities available in the commercial edition are:
MySQL Workbench has five main functions: Database design (data modeling)This involves creating simple to complex entity-relationship (ER) models. Reverse engineering creates a database from ER models. Forward engineering creates an ER model from a live database. Developing SQLMySQL Workbench has a built-in SQL editor with syntax highlighting and auto-complete. It is used to interact with the MySQL Server. AdministrationSome of the MySQL Workbench database administrative functions are:
MySQL Workbench has a visual performance dashboard. The visual performance dashboard enables database administrators to view key performance indicators. Below is a screenshot of the MySQL Workbench visual performance dashboard. Image source Data migrationMySQL Workbench is used to migrate databases from other relational database management systems (RDBMS). Some of the supported RDBMS are PostgreSQL, MS SQL Server, SQLite, MS Access, Sybase, and Sybase SQL Anywhere. MySQL enterprise supportMySQL Workbench enterprise edition supports MySQL enterprise products. In this tutorial, the focus will be on database design. Setting up MySQL WorkbenchWorkbench is one of the MySQL products. Use MySQL Installer to manage MySQL products installations. Find the list of MySQL Workbench supported platforms on MySQL official website. For the MySQL Workbench hardware requirements, check the image below. Image source Installing MySQL Workbench on WindowsDownload MySQL Installer from the official website. Install MySQL Workbench using the downloaded installer. For this installation, I recommend the default configurations, as shown in the screenshot below. The You can find more detailed installation guidelines for MySQL Workbench on MySQL Workbench Manual. Verifying MySQL Workbench installationLaunch MySQL Workbench. You can do this from the installation wizard.
Make sure there is a connection to the MySQL Server local instance, as shown in the screenshot below. If there is no connection, click the Provide the connection details. The created connection will be displayed, as shown in the screenshot below. Database design with MySQL WorkbenchThis section will create a new ER model and then translate it into a physical MySQL database. On MySQL Workbench, navigate to Save the model. Double click After adding a new diagram, a new window will be opened, as in the screenshot below. ScenarioIn this tutorial, we will model and create a database that will be used to keep book details. The database should store books with author and publisher details. We will skip the database normalization process details. The final database will have three main entities with attributes, as shown below:
We will use the information in the tables below to design the ER model. All the column names have been defined. Primary keys, foreign keys, and datatypes are also outlined. Book table column namedata typecan be nullindex typeauto_incrementidintegernoprimary keyyesisbnvarchar(45)nouniquepublisherintegernoforeign keyauthorintegernoforeign keytotal_pagesintegernopublication_yearyear(4)notitlevarchar(255)noAuthor table column namedata typecan be nullindex typeauto_incrementidintegernoprimary keyyesfirst_namevarchar(45)nolast_namevarchar(45)noPublisher table column namedata typecan be nullindex typeauto_incrementidintegernoprimary keyyesnamevarchar(45)noThe relationships between the entities are as below:
Using MySQL Workbench, we will design an enhanced entity-relationship (EER) diagram. MySQL Workbench allows us to create tables, edit the attributes, and create relationships between the tables. The visual design interfaceThe diagram below shows a MySQL Workbench design window screenshot. The window has different panels highlighted in different colors. The vertical toolbar panelThe vertical toolbar has different tools used in creating EER diagrams. The screenshot below shows all the tools. Hovering the mouse pointer on each tool will show the name or the function of each tool. There are six tools used to create different types of relationships in MySQL Workbench. Add tablesWe are going to add three tables to the EER model. The animation below shows the process of adding a table and the columns. To add a table, follow these steps:
Your EER diagram should look as shown below. Add relationshipsWe will add two different relationships to the EER diagram. One-to-many relationshipThere is a one-to-many relationship between the book and the publisher. We will use the relationship tools to add relationships. To create a one-to-many relationship, make sure that one of the tables has a primary key. Select the appropriate relationship tool. In this case, we are going to use the one-to-many non-identifying relationship. Click the table on the “many” side. In this case, it is the book table. Click the table containing the referenced key. In this case, it is the publisher table. A foreign key is created on the book table with the default name as Many-to-many relationshipThere is a many-to-many relationship between the book and the author. Select the many-to-many relationship tool. Click on the book table, then click on the author table as shown in the animation below. A bridge table with the name After creating the relationships, the EER diagram will be as shown in the screenshot below. You can find the EER diagram workbench file created in this tutorial on Github. Forward engineering with MySQL WorkbenchThe visual database model created can be transformed into a physical database. This process is known as forward engineering. SQL code is generated and executed on a target MySQL Server. This is easier than writing the code manually. Step 1To launch forward engineering wizard, Navigate to Step 2Create a new connection to MySQL Server or select an existing one, as shown in the screenshot below. Click Step 3The wizard gives us SQL export options. For this exercise, use the default selected options. Step 4Select the objects you would like to include in the EER diagram. These will include tables, views, routines, users, and triggers. In this exercise, we only have tables. Make sure the option to import 4 table objects is selected, then click Step 5In this step, we are provided with the generated SQL script. Find the SQL file generated in this tutorial on Github. Step 6This is the final step. Click finish to commit. The generated SQL file is used to create a physical database in the connected MySQL Server. To view the database created on MySQL Workbench, navigate to Reverse engineering with MySQL WorkbenchReverse engineering enables us to have a better view of an existing database. A physical database is converted to an EER diagram. We will be reverse engineering the database we created earlier. Reverse engineering can be done while using a MySQL Create Script or by using a live database. In this tutorial, we will use the live database we created in the section. Follow these steps: Step 1Navigate to Step 2Create a new connection to the MySQL Server or select an existing one, as shown in the screenshot below. Click Step 3Review the information displayed and make sure that the connection was successful, then click Step 4Select the schema you would like to reverse engineer. In this case, select Step 5The results of the tasks carried out are displayed in the wizard below. Review the results, then click Step 6We are prompted to select the objects to reverse engineer. By default, all the available objects are selected. Leave the default options, then click Step 7The wizard shows the reverse engineering progress. In the screenshot below, the process was successful. In case of an error, check error details by clicking Click Step 8This step shows the summary of the objects generated. In this case, we have four table objects. Click OutputThe EER diagram below is generated. You can save it for later use. ConclusionMySQL Workbench is such a useful tool. It can be used by MySQL database administrators, system developers, and database developers. You can create a database from an ER model without writing MySQL statements. At first, the tool may seem complex to use, but with time it gets easier. Practice makes perfect. How do I view all tables in MySQL workbench?To access the inspector, right-click a schema and select the Schema Inspector. Each tab lists topic-oriented information in categories, such as tables, indexes, and triggers.
How do I view all tables in a database?How to display all the tables from a database in SQL. SELECT table_name FROM INFORMATION_SCHEMA. TABLES WHERE table_type = 'BASE TABLE' SELECT name FROM sys. ... . -- This returns all the tables in the database system. ... . -- Lists all the tables in all databases SELECT table_name FROM information_schema.. What is the command to view all tables in MySQL?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. ... . Step 2: Next, choose the specific database by using the command below:. Step 3: Finally, execute the SHOW TABLES command.. Output:. Syntax.. Which command is used to view the list of tables in a database?SHOW TABLES lists the non- TEMPORARY tables in a given database. You can also get this list using the mysqlshow db_name command.
|