MySQL workbench tutorial (beginner Edition)

Source: Internet
Author: User
MySQL workbench is a visual database design tool recently released by MySQL AB. This tool is a dedicated tool for designing MySQL databases. MySQL workbench has many functions and features. This article, written by djoni darmawikarta, shows some of them through an example. We will create a physical data model for an order system, where the order system can be a sales order or an order, and use forward-Engineer (forward engine) generate our model into a MySQL database. MySQL workbench is a visual database design tool recently released by MySQL. This tool is a dedicated tool for designing MySQL databases. The physical data model you created in MySQL workbench is called. A physical data model is a data model for a specific RDBMS product. The model in this article will have some unique MySQL specifications. We can use it to generate (Forward-engineer) database objects. In addition to tables and columns (fields), we can also contain views. MySQL workbench has many functions and features. This article, written by djoni darmawikarta, shows some of them through an example. We will create a physical data model for an order system, where the order system can be a sales order or an order, and use forward-Engineer (forward engine) generate our model into a MySQL database. In our example, the physical model created using MySQL workbench looks like this: create order schema first let's create a solution to save the physical model of the order. Click the + button (marked in red) to change the default name of the new solution to "order. Note that when you type a solution name, the label name on physical schemata also changes-this is a good feature. The Order Scheme is added to the catalog (Red circled in the figure ). Close the schema window after renaming the solution. To create an order table, we now create three tables in the order model: Order table and its two subtables sales_order and purchase_order. First, make sure that you have selected the label of the Order scheme, so that the table we created will be included in this scheme. The table we want to create is displayed as an eer chart (EER = enhanced entity relationship ). Therefore, double-click Add digoal. Click the table icon, move the mouse to the eer digoal area, and click the cursor at the position where you want to place the first table. For the other two tables, repeat the preceding operation. You can drag a table to move its position. In the next step, we need to perform some operations on table 1. These operations are completed through the table editor of workbench. To open the table Editor, right-click Table1 and select the edit Table menu. Enter the table name order in table 1. Next, add columns (fields ). Select the columns label. Change the column name (field name) idorder to order_no. Select the Data Type int in the drop-down list box. We hope that the value of the order_no column can be automatically controlled by the MySQL database. Therefore, we select the AI column (Auto increment-auto increment). AI is a feature of the MySQL database. You can also specify other physical attributes of a table, such as its collation attribute. You can also specify other advanced options of the table, such as trigger and portioning (corresponding to the trigger and partioning labels respectively ). Note: In digoal, Table 1 has changed to order, and it has a column (field) order_no. You can also see three tables in the directory. Black spots on the right of the table indicate that they are included in a chart. If you expand order, you can see the order_no column. Because we define it as the primary key, there is a key icon on the left side of it. Return to the Table Designer and add the other two columns (fields): order_date and order_type. Order_type can have two values: s indicates the sales order, and P indicates the purchase order. Because sales orders are more commonly used, the default value of columns (fields) is S. You can double-click the white area below the last column to add the next field. Use the same method to create the sales_order table and its columns (fields ). Finally, create the purchase_order table and its columns (fields ). We have created three tables to create a link. This is not the end; we still need to create their relationships. Sales_order is the subtable of order, which means they are, sales_order is the subtable, order is the parent table, and the order key is moved to sales_order. Therefore, select (click) 1:1 identifying relationship icon, click in the sales_order table, and then click in the order table. Note: When you click a table, the icon changes to a hand shape with a relationship. The relationship is set in this way. The order_no primary key is moved to the sales_order table and serves as its primary key. Next, create the relationship between purchase_order and order. The relationship is still. We have now completed the design of the relationship between tables; Save Our model as order. mwb. the purpose of the data model design in this article is to build a MySQL database. We will first generate DDL (SQL create script) and then execute this script. From the file | export menu, select forward engineer SQL create script. Finally, run the saved SQL create script. MySQL workbench itself does not have the ability to execute this script; we can execute it in the MySQL command console. You can also check whether the table has been created. Summary This article shows you how to visually create a MySQL physical data model in MySQL workbench and use it to create a MySQL database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.