Turn from: Http://www.cnblogs.com/yqskj/archive/2013/03/01/2938027.htmlMySQL workbench is a Visual Database design tool that MySQL AB recently released. This tool is a dedicated tool for designing MySQL databases. MySQL Workbench has a lot of features and features, and this article, written by Djoni darmawikarta , shows some of them through an example. We will establish a physical data model for an order system, where the order system can be either a sales order or an order, and use forward-engineer (forward engine) build 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. What you build in MySQL Workbench 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 specifications for MySQL. We can use it to generate (forward-engineer) database objects, which can contain views in addition to tables and columns (fields). MySQL Workbench has a lot of features and features, and this article, written by Djoni Darmawikarta, shows some of them through an example. We will establish a physical data model for an order system, where the order system can be either a sales order or an order, and use forward-engineer (forward engine) build our model into a MySQL database. The physical model created in our example using MySQL Workbench looks like this: create an order schema first let's create a scenario that holds the physical model of the order. Click the + button (where red marks) change the new scheme by default name for the order. Note that when you type the scheme name, the label name on the physical schemata changes as well-this is a good feature. The order scheme is added to the catalog (the red circled part of the figure). close the schema window after renaming the scheme. Create an order form we now create three tables in the Order model: order Table and its two sub-tables Sales_order and Purchase_order. First, make sure that you have selected the label for the ORDER scheme, so that the table we created will be included in this scenario. The table we are going to create is shown as a EER chart (EER = enhanced Entity relationship). So, double-click the Add Diagram button. Click the table icon, then move the mouse to the EER Diagram area and click the mouse 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 and dragging. Next, we're going to do some work on table1, which is done through the Workbench table editor. To open the table editor, simply right-select table1 and select the Edit Table menu. Type the Table1 table name ORDER. 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 want the value of the Order_no column to be automatically controlled by the MySQL database, so we select the AI column (auto increment--self-increment). ai is a feature of the MySQL database. You can also specify other physical properties of the table, such as its Collation property, and of course you can specify other advanced options for the table, such as Trigger and portioning (respectively, corresponding to trigger and partioning tags). Note that at this point, in diagram, our table table1 has changed to order, and it has a column (field) order_no. In the table of contents, you can also see that there are three of tables. Black dots on the right side of the table to indicate that they are contained 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. Back to Table Designer, add two other columns (fields): Order_date and Order_type. Order_typeThere can be 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 columns (fields) is S. You can add the next field by double-clicking the mouse in the white area below the last column. use the same method to create the Sales_order table and its columns (fields). Finally, create the Purchase_order table and its columns (fields). Create a relationship we have created three tables. It's not over here, we still need to create their relationship. sales_order is the child table 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) the 1:1 Identifying Relationship icon, click on the Sales_order table, and then click on the ORDER table. Note that when you click a table, the icon changes to a 1:1-relationship hand. The 1:1 relationship is set in this way; the Order_no primary key is moved to the Sales_order table and 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 table and table; Save our model as order.mwb. generate DDL and database Finally, the purpose of the data model design in this paper is to build MySQL database. We will first generate the DDL (SQL CREATE script) and then execute the script. from file | export menu, select Forward Engineer SQL Create script. Finally, execute the saved SQL create script. The 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 see if the table has been created. Summary This article shows you how to build a MySQL physical data model visually in MySQL Workbench and use it to create aA MySQL database.
(GO) MySQL Workbench Tutorial (introductory version)