How to use MySQL Workbench (text) _mysql

Source: Internet
Author: User

Mysqlworkbench is a recently released Visual Database design tool for MySQL AB. This tool is a dedicated tool for designing MySQL databases.

Download Address: http://www.jb51.net/database/29494.html

Mysqlworkbench has many functions and features; This article, written by Djonidarmawikarta, shows some of them through an example. We will build a physical data model for an order system, where the order system can be either a sales order or a forward-engineer, and use the forward engine to make our model a MySQL database.

Mysqlworkbench is the most recently released Visual Database design tool for MySQL. This tool is a dedicated tool for designing MySQL databases.

What you build in Mysqlworkbench is called the physical data model. A physical data model is a data model for a particular RDBMS product; The model in this article will have some unique MySQL specifications. We can use it to generate (forward-engineer) database objects, which can contain views in addition to tables and columns (fields).

Mysqlworkbench has many functions and features; This article, written by Djonidarmawikarta, shows some of them through an example. We will build a physical data model for an order system, where the order system can be either a sales order or a forward-engineer, and use the forward engine to make our model a MySQL database.

The physical model that we created using MySQL Workbench in our example looks like the following image:

Create an order Schema

Let's first create a scheme to save the physical model of an order. Click on the + button (Red mark place)

Change the new scheme default name to order. Note that when you type the scheme name, the label name on the physical schemata will also change-this is a good feature.

The order scheme is added to the directory (Catalog) (the red circled part of the figure).

Closes the schema window after renaming the scheme.

Create Order Table

We now create the three tables in the order model: the Orders table and its two child tables Sales_order and Purchase_order. First, make sure you have selected the label for the order scheme so that the table we create will be included in this scenario.

The table we are going to create is shown as a EER chart (EER = Enhanced entityrelationship). So, double-click the Add Diagram button.

Click the table icon, then move the mouse to the EER diagram area, and click where you want to place the first table.

For the other two tables, repeat the above action. You can move the position of the table by dragging it.

Next, we'll do something about Table1, which is done through the Workbench table editor. To open the table editor, just right-click to select Table1 and select the Edit Table menu.

Type the Table1 table name order.

Next, add the 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 want the value of the Order_no column to be automatically controlled by the MySQL database, so we select the AI column (autoincrement--).

AI is a feature of the MySQL database.

You can also specify other physical properties of the table, such as its collation properties, and of course you can specify other advanced options for the table, such as Trigger and portioning (corresponding to trigger and partioning tags, respectively).

Note that at this point, our table table1 has changed to order in diagram, and it has a column (field) order_no. In the table of contents, you can also see that there are three tables.

Black dots on the right side of the table, indicating that they are contained in a chart.

If you expand the 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.

Go back to the Table designer and add two more columns (fields): Order_date and Order_type. Order_type can have two values: S represents a sales order, and p represents a purchase order. Because sales orders are more commonly used, we specify that the default value for the column (field) is S.

You can add the next field by double-clicking the mouse in the white area of the last column.

Use the same method to create the Sales_order table and the Columns (fields) in it.

Finally, create the Purchase_order table and the Columns (fields) therein.

Create a relationship

We have created three tables. It's not over here; we still need to create their relationship.

Sales_order are child tables of order, meaning they are 1:1, Sales_order is a child table, order is the parent table, and the order key is moved to Sales_order. So, select (click) 1:1 the Identifyingrelationship icon, click on the Sales_order table, and then click on the Order table.

Note that when you click the table, the icon changes to a 1:1-relationship hand.

The 1:1 relationship is set, and the Order_no primary key is moved to the Sales_order table as its primary key.

Next, create a purchase_order to order relationship, which is still a 1:1 relationship.

We have now completed the design of the relationship between tables and tables; Save our model as ORDER.MWB.

Generating DDL and databases

Finally, the purpose of designing the data model in this paper is to build MySQL database. We will first generate the DDL (Sqlcreate script) and then execute the script.

From File | Export menu, select Forward Engineer SQL createscript.

Finally, execute the saved SQL CREATE script. MySQL Workbench itself does not have the ability to execute this script, and we can execute it in the MySQL command console.

You can also check to see if the table has been created.

Summarize

This article shows you how to visually build the MySQL physical data model in MySQL Workbench and use it to create a MySQL database.

Related Article

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.