MySQL Basics (30) Use of PowerDesigner

1 Use of PowerDesigner

PowerDesigner is a database modeling tool commonly used by developers. Users can use this software to easily create 数据流程图, 概念数据模型, 物理数据模型and . It covers almost the entire process of database model design. It is a complete set of tools provided by Sybase for enterprise modeling and design. Integrated enterprise-wide modeling solution.

1.1 Start interface

The PowerDesigner version currently in use is 16.5. When you open the software, you will see this page. You can choose Create Model, or you can choose Do Not
Show page Again. You can also create it yourself after opening the software! It all depends on personal preference. I will not display this page in subsequent studies.
Insert image description here
"Create Model" functions like an ordinary file, which can be stored individually or in categories.

“Create Project” functions like a folder, responsible for centrally classifying and storing related files.

1.2 Conceptual data model

There are 4 commonly used models, namely 概念模型(CDM Conceptual Data Model), 物理模型(PDM,Physical Data Model), 面向对象的模型(OOM Objcet Oriented Model)and 业务模型(BPM Business Process Model). We first create a conceptual data model.

Insert image description here
Click OK above, and the conceptual model 1 on the left side of the picture below will appear. You can customize the name of the conceptual model. The most commonly used conceptual models are Entity and Relationship as shown in the picture.

Insert image description here

Entity

Select the Entity function in the right box, and the following box will appear. It should be noted that when writing the name, the code will be completed by itself. The name can be in English or Chinese, but the code must be in English.
Insert image description here

Populate entity fields

After filling in the name and code in General, you can click Attributes to set name, code (field name in the database), Data Type (data type), length (length of data type)

  • Name: The entity name is generally in Chinese, such as forum users
  • Code: Entity code, usually in English, such as XXXUser
  • Comment: Comment, detailed description of this entity
  • Code attribute: code name, usually English UID DataType
  • Domain field, indicating the attribute value range. For example, you can create a 10-character address domain.
  • M: Mandatory mandatory attribute, indicating that this attribute is required. Can not be empty
  • Whether P:Primary Identifer is the primary identifier, indicating the unique identifier of the entity
  • D:Displayed is displayed, all are checked by default

Insert image description here
The above figure illustrates the naming method of name and code.
Insert image description here

Set primary identifier

If you do not want the system to automatically generate identifiers but set them manually, switch to the Identifiers tab, add a row of Identifiers, then click the "Properties" button in the upper left corner, and then click "Add Row" in the pop-up Identity Property Settings dialog box. ” button to select the attributes used in this logo. For example, set the student ID as the identifier of the student entity.
Insert image description here

Enlarge model

The created conceptual data model is as shown in the figure, but the created font is very small. Readers can hold down the ctrl key and slide the sliding button of the mouse to enlarge the abbreviation font. At the same time, you can also see that the main identifier has an * sign. logo, and also displays the visible attributes name, Data type and length.
Insert image description here

entity relationship

Create a class entity in the same way (it is important to note that after clicking the function button on the right, you need to click the button in the mouse pointer state or right-click the mouse, otherwise it is easy to operate randomly, just pay attention to this), Then use the Relationship button to connect the relationship between students and classes, creating a one-to-many (class to students) or many-to-one (students to class) relationship.
As shown in the picture,
Insert image description here
it should be noted that clicking the Relationship button connects the class and the student, which is a line. Then double-click this line to edit. After the name and code are changed in the General area
Insert image description here
, You can check the relationship between the class and the students in the Cardinalities section. You can see that there is a line at one end of the class and three lines at the student end, which means that the class has a one-to-many relationship with the students, that is, a one-to-many relationship. Click Apply, and then After confirming, you can
Insert image description here
practice one-to-many and many-to-one and many-to-many exercises. As shown in the figure below, the teacher entity is the same as described above. You can modify the name, data type, etc. to what you need. Just meet the project development needs. (Comment is an explanation. You can write relevant introductions and explanations.) What you
Insert image description here
need to note about many-to-many is that you can manually click the button to adjust the relationship as a many-to-many relationship or a many-to-many relationship, and then click Apply and OK.
Insert image description here
In summary, the design of the simplest conceptual data model of students, classes, and teachers needs to be considered. The type of data and the primary identification code need to be considered, and whether it is empty. Whether the relationship is one-to-one, one-to-many, or many-to-many, you need to plan and then design it, and then it will be ok.
Insert image description here

1.3 Physical data model

The above is the conceptual data model. Next, we will introduce the physical data model. The physical data model will be often used in the future. Open PowerDesigner, then click File–>New Model and select the physical data model as shown in the figure below. The name of the physical data model starts with itself, and then selects the database you are using.

Insert image description here
The main page is created as shown in the figure, but the buttons on the right are slightly different from the conceptual model. The three most commonly used physical models are, , ; first click the table(表)table view(视图)button reference(关系)on
Insert image description here
the right and then click on the new physical model to create a new one. A table, and then double-click to create a new table as shown below. Fill in the name and code of General as you need, and click Apply), as shown below: Then click
Insert image description here
Columns, and set it as shown below. It is very simple. What you need to pay attention to is P (primary Primary key), F (foreign key), M (mandatory, meaning it cannot be empty).
Insert image description here
Set the auto-increment of the student ID here (the auto-increment in MYSQL is AUTO_INCREMENT). The same is true for the class number, so I won’t go into details!
Insert image description here
Just check this point below and the auto-increment is set.

Insert image description here
After everything is completed, it will look like the picture below.

Insert image description hereThe class physical model can be created in the same way as shown in the picture
Insert image description here
Insert image description here
below. After completion, the
Insert image description here
above settings are as shown in the picture below. Then the following is the key point. Click the button on the right to refer to this button, because the class is one-to-many for students. , so the mouse is pulled from the student to the class as shown in the figure below. The student table will change. A row is added to the student table. This row is the primary key of the class table and serves as the foreign key of the student table, linking the class table and the student table. (Look closely and you can see the difference.)

Insert image description here
After completing the above operation, you can double-click a line in the middle to display the following picture. Just modify the name and code. However, it should be
Insert image description here
noted that the result displayed after the modification is as shown below. There is no way to directly resemble the conceptual model. , it will be displayed on the middle line after modification, you can understand it yourself.
Insert image description here
After learning the many-to-one or one-to-many relationship, next learn the many-to-pair relationship. In the same way, you can build the teacher table yourself. I will not describe it here. Remember that the teacher number will be incremented. Once it is built, it is as shown in the figure below.
Insert image description here

The following is the key to the many-to-many relationship. Since the many-to-many relationship of the physical model requires an intermediate table to connect, as shown below, only set one field, the primary key, and auto-increment. Click Apply, then set Columns, and only add one field. This is the
Insert image description here
setting
Insert image description here
. The field is incremented. It has been described several times before.
Insert image description here
After setting it up, it is shown in the figure below. It should be noted that the side with an arrow is one, and the side without an arrow is many. That is, the one-to-many and many-to-one relationship needs to be clarified. Students There can also be many teachers, and teachers can also have many students, so both students and teachers can be subjects;

Insert image description here
You can see the changes in the relationship tables between students and teachers after adding the relationship.
Insert image description here

1.4 Convert conceptual model to physical model

1. First open the conceptual model diagram as shown in the figure below, and then click Tool, as shown in the figure below. The
Insert image description here
clicked page is as shown below. The name and code have been changed from conceptual model 1 to physical model 1.
Insert image description here
After completion, as shown in the figure below, Open the modified physical model by yourself. It should be noted that the data types of these tables have changed by themselves, and there are two primary keys in the intermediate table, that is, double primary keys.
Insert image description here

1.5 Convert physical model to conceptual model

The above introduces the conversion of the conceptual model to the physical model. The following introduces the conversion of the physical model to the conceptual model (just click on the picture below)
Insert image description here
and then the interface as shown below will appear. Then change the physical model to the concept and click Apply to confirm.

Insert image description here
After clicking Confirm, the page shown in the figure below will open automatically. Observe the changes yourself. If converted to Oracle, the data type will change, such as Varchar2, etc.);

Insert image description here

1.6 Physical model export SQL statement

The following introduces the physical model export SQL statement (click the Generate Database of the Database button or press ctrl+G).
Insert image description here
After opening, as shown in the figure, modify the location of the SQL statement and the name of the generated file to select
Insert image description here
the table that needs to be exported in Selection. , then click Apply and Confirm

Insert image description here
After completion, it will appear as shown below. You can click the Edit or close button.
Insert image description here
From then on, the exported sql statement is completed, and you can view the exported sql statement at the location you specified; PowerDesigner will be used to make requirements during the project development process in the future. Analysis and database design are very convenient and fast.

Guess you like

Origin blog.csdn.net/zhufei463738313/article/details/130642019