Detailed explanation of PowerDesigner database modeling

Table of contents

I. Introduction

2. Overview of PowerDesigner

2.1 Core capabilities of PowerDesigner

2.1.1 Integrating Multiple Modeling Capabilities

 2.1.2 Automatic Code Production Capability

 2.1.3 Powerful reverse engineering capability

2.1.4 Scalable Enterprise Library Solution

2.2 Several models commonly used in PowerDesigner

2.2.1 Conceptual model

2.2.2 Logical Data Model

2.2.3 Physical model 

2.2.4 Object-Oriented Model

2.2.5 Business Process Model

Three, PowerDesigner installation

Fourth, the use of PowerDesigner core functions

4.1 Create a data model

4.1.1 Method 1

4.1.2 Method 2

4.2 Create a data table

4.2.1 Create three tables

4.2.2 Set fields and attributes for three tables

4.3 Set the association relationship of the table

4.3.1 Set the foreign key of user table and role table

4.3.2 Modify the primary and foreign key cascading relationship

4.4 Export database

4.4.1 Export sql script

4.4.2 Create tables using sql

4.5 Reverse Engineering

4.5.1 What is reverse engineering

4.5.2 Reverse engineering steps

4.5.3 pd connects to external data sources

4.6 Conversion of different database models

4.6.1 Reverse engineering and importing a sql file

4.6.2 Generate a new PDM file based on the current PDM

Five, written at the end of the text


I. Introduction

For students of back-end development, PowerDesigner, a database modeling tool, should be familiar. Using PowerDesigner can help developers quickly complete database modeling-related work, thereby helping to improve the development efficiency of the entire software project.

2. Overview of PowerDesigner

PowerDesigner is a software of Sybase Corporation, which can be used to analyze and design the system conveniently, almost including the whole process of database model design. Use PowerDesigner to make data flow diagrams, conceptual data models, physical data models, and object-oriented models. The output of these models is also a work that needs to be completed before formal coding in a standard development process. (PowerDesigner is hereinafter referred to as pd)

2.1 Core capabilities of PowerDesigner

2.1.1 Integrating Multiple Modeling Capabilities

  • Data model (E/R, Merise) entity relationship diagram;
  • Business models (BPMN, BPEL, ebXML);
  • application model (UML);

 2.1.2 Automatic Code Production Capability

PowerDesigner can generate a variety of codes through the data model, such as

  • SQL script (supports more than 50 database systems, such as mysql, pg, oracle, etc.), which can be directly imported into the database for use; 
  • Java, through object-oriented modeling, can quickly output basic Java object entity class files, which can be used with simple modifications;
  • .NET etc...

 2.1.3 Powerful reverse engineering capability

Using PowerDesigner, you can design, convert, and migrate library tables across languages ​​and databases, and support online connection to mysql for design. These are very practical functions.

2.1.4 Scalable Enterprise Library Solution

With strong security and version control capabilities, it can support multi-user collaborative design

2.2 Several models commonly used in PowerDesigner

Before actually starting to use pd, it is necessary to have a comprehensive understanding of the several core models it provides.

2.2.1 Conceptual model

Conceptual Data Model (CDM), CDM represents the overall logical structure of the database, independent of any software or data storage structure.

  • A conceptual model often includes data objects that are not yet implemented in the physical database; 
  • It gives a formal representation of the data that runs the program or business activity;
  • The conceptual data model is the end user's view on data storage, reflecting the user's comprehensive information needs; 
  • Regardless of physical implementation details, only the relationship between entities is considered;

CDM is a tool suitable for the system analysis phase. 

2.2.2 Logical Data Model

Logical Data Model (LDM), which helps analyze the structure of an information system, is also independent of the implementation of a specific physical database. 

 The LDM is more specific than the Conceptual Data Model (CDM), but does not allow defining views, indexes, and other details that are handled in the Physical Data Model (PDM). The logical data model can be regarded as an intermediate step in database design, it is between the conceptual data model and the physical data model.

2.2.3 Physical model 

The physical model, or PDM, is a database design tool used to define the physical structure and data query in detail. Different types of diagrams can be used in PDM, depending on the type of target database being designed. 

The main purpose is to generate a specific DBMS script from the real world model established in CDM, generate a storage structure for storing information in the database, and ensure the integrity and consistency of data in the database. PDM is a tool suitable for the system design phase. 

2.2.4 Object-Oriented Model

Object-oriented model (OOM), which is a necessary model in the model design of Java as a development language. Specifically,

  • An OOM consists of a series of packages, classes, interfaces, and their relationships;
  • These objects together form the class structure of all (or part of) a logical design view of a software system;
  • An OOM is essentially a static conceptual model of a software system;

OOM includes use case diagrams, sequence diagrams, and class diagrams. Finally, five results are generated in the dark part of the figure below, namely, model warehouse (Repository), model report (Report), database SQL script, user database structure and application code.

2.2.5 Business Process Model

The business process model is BPM. BPM describes various internal tasks and internal processes of the business. Users can clearly see the relationship and mutual influence of these tasks and processes through the BPM model;

  • BPM is a conceptual model that describes business logic and rules in detail from the perspective of business personnel, and uses flowcharts to represent the processing, processes, messages and collaboration protocols from one or more starting points to the end points;
  • Through BPM, the behavior and requirements of the system can be described, and the conceptual organization structure of the object can be represented graphically, and then the required documents can be generated;
  • As a conceptual level module, BPM is suitable for the system analysis stage of the application system to complete the system requirement analysis and logic design;

PowerDesigner BPM includes 3 flow diagrams

1) Process hierarchy diagram: Identify the functions of the system in a hierarchical manner.

2) Business process diagram (Business process diagram): used to analyze the specific implementation mechanism of a/group process.

3) Process service diagram: Express the business flow chart in the form of business services.

Three, PowerDesigner installation

The current mainstream version of PowerDesigner is 16.5, and the details of the installation will not be described in detail. There are many online installation tutorials, and interested students can check it out.

Fourth, the use of PowerDesigner core functions

pd has developed so many functions today, even a veteran in the rivers and lakes may not be involved in all the functions involved in it. In fact, pd is mainly used for database modeling in the database design stage in daily development Therefore, mastering its core database modeling is actually enough to deal with most scenarios. Next, I will make an in-depth description of the technical points related to database modeling.

4.1 Create a data model

Before designing a table, there needs to be a model to carry it, so first a data model needs to be created;

4.1.1 Method 1

Via File -> New Model -> New Physical Model;

 

4.1.2 Method 2

Click the icon below the file to create

 

After inputting the model and clicking ok, a model is created under the current project space;

4.2 Create a data table

After having the data model, the next step is to design the table structure. In order to facilitate the subsequent operation instructions, we combine a relatively real scene, assuming that there are 3 tables that need to be designed, user table, role table, and user role association table. The three tables represent the relationship between users and roles in actual business scenarios, and the three tables are user, role, and role_user;

4.2.1 Create three tables

Select the table icon in the floating menu on the right, and then click in the work area, a table will appear, here need three tables, click 3 times;

4.2.2 Set fields and attributes for three tables

Double-click the current table to enter the table design area below. There are many menu bars in it. At present, the main focus is on the menus related to the fields of the table;

Enter the Columns menu to design the fields. The attribute settings of each field mainly include the following:

After the field design is completed, click Apply and confirm. At this time, the user table is designed. If you want to add or modify the fields of the table later, you can double-click the table to enter the following interface again for operation;

Design the role and role_user tables in the same way as above

4.3 Set the association relationship of the table

In the current Internet project database design, the industry is gradually diluting the concept of primary and foreign keys, because the existence of foreign keys will cause a lot of trouble in the subsequent business process, especially when it comes to data migration. Quite a painful thing, but an important purpose of the PD modeling stage is to present the business relationship behind the table through the data table, and this relationship needs to be reflected in the PD table through the primary and foreign keys;

Taking the above three tables as an example, students who understand the business may also see the relationship between the three, but what about other businesses? How can you quickly see it? Let's set up the primary and foreign key relationships of the three tables.

4.3.1 Set the foreign key of user table and role table

Click the icon on the right to set the primary and foreign keys. When setting the relationship between the two tables, you only need to connect the two tables with a line, and pay attention to the direction of the arrow;

 Generally speaking, when you set up the connection, pd will automatically find the primary and foreign key relationship between the two. From the effect of the above connection, after the connection is completed, the user ID and role in the user table are respectively After the ID of the table, a fk logo appears, indicating that this field is also a foreign key;

How to confirm that a foreign key relationship is really established between the two? You can double-click the connection in the middle to switch to the Preview column, and you can see a line of SQL statements in it;

 The sql statement is as follows. It is not difficult to see that this sql specifies the cascading relationship between the two tables when the table is built;

alter table user add constraint FK_Reference_3 foreign key (id)
      references role_user (id) on delete restrict on update restrict;

4.3.2 Modify the primary and foreign key cascading relationship

By default, when the two tables are connected by primary and foreign keys, when generating the database script, the relationship between the two tables is specified through a sql, but by default, this method belongs to the Strongly related relationship, as mentioned above, in real development, we don't want the two tables to have too strong a binding relationship, which will cause trouble for subsequent maintenance. This requires manual modification of this cascading relationship, what should I do? ? Just follow the steps below;

Click the connecting arrow to enter the following interface, check the none radio box, and then click OK;

 It is not enough to complete this step, but also need to remove those sql that set the reference relationship in the final generated database script;

When using PD to set the foreign key relationship, sometimes after the online connection, the foreign key field is not accurate or you want to change the foreign key field, at this time you can switch to the Joins column for the following settings;

4.4 Export database

After designing the data table, the next step is to export the sql script that the database can execute, which is also very simple in pd, just follow the steps below;

4.4.1 Export sql script

Click: Database -> Generate Database

Set the location and name of the exported sql

 In the Preview column, the original table creation sql is displayed;

After the export is complete, you can see the original sql script file in the local data directory;

4.4.2 Create tables using sql

Import the above sql in navicat,

After the import is successful, you can see the following tables, and through the reverse relationship map of navicat, you can see the primary and foreign key relationships between the three tables;

4.5 Reverse Engineering

4.5.1 What is reverse engineering

Reverse engineering (also known as reverse technology) is a product design technology reproduction process, that is, reverse analysis and research on a target product, so as to deduce and obtain the processing flow, organizational structure, functional characteristics and technical specifications of the product, etc. design elements to produce products that are similar in function but not identical.

4.5.2 Reverse engineering steps

Select: File -> Reverse Engineering -> Database, what to do here is to modify the design of the external sql script by using reverse engineering, and then re-export;

Enter the following interface, fill in a name

After clicking OK, two methods are provided here, one is based on the existing database script, and the other is to directly configure and connect to external data sources;

Here choose to use the local sql script, select the sql file exported above;

After clicking OK, you can see that the previous data table model has been imported, and you can continue to design and use based on this model;

4.5.3 pd connects to external data sources

Sometimes in order to reduce the trouble of loading sql scripts, you can directly connect to external data sources, especially in some cases where the original sql file is not allowed to be exported. This is a very practical way. The specific operation steps are as follows;

Click: Database -> Configure Connections...

Click the button below to set the data source connection;

After clicking OK, select the system data source

After clicking the next page, select Mysql ODBC (this has pitfalls, which will be discussed later), if you want to connect to other data sources, just select the corresponding driver;

Finally, come to the following interface, set the configuration information of your data source connection, click Test Connection, and it will be ok after success;

Click Reverse Engineering again, and at the next step, select a practical data source;

 After clicking OK, you will come to the following interface, and check the table you want to import as needed;

 

Click OK, and you can see that the external data table has been imported. This method is equivalent to directly connecting to the database for import. If there are many tables, this process may be a bit slow;

4.6 Conversion of different database models

In a real project, you may face the following scenario. At the beginning, your project uses mysql, but then suddenly your project needs to support other data sources, such as oracle, or postgresql, etc. At this time, you are faced with The first problem is to change the database, which is a headache, especially for those projects with a lot of data tables, not to mention data migration, just redefining the table structure is not a small workload . But if you think of using pd to convert at this time, congratulations, this will save you a lot of time, how to do it? See the specific steps below.

The complete operation process is as follows

4.6.1 Reverse engineering and importing a sql file

Still take the database file exported to the local as an example

 

You can choose to use local scripts, or directly connect to the database

 Effect after import

 

4.6.2 Generate a new PDM file based on the current PDM

 Here, choose the new database type according to your actual situation. For example, here I choose postgresql;

 

After confirming, you can see a new PD file in the menu on the left, and at the same time, you can see that the type of the field "User ID" in the data table on the right has also changed from int in mysq to in4 in pg

export sql file

 

 

After clicking OK, check the exported sql file, and then import it to the pg database

 

So far, the conversion of the model database from mysql to pg has been completed through the above process.

Five, written at the end of the text

Database design is a very important part of the complete project development cycle. Although more and more Internet products are diluting the status of databases in fast iterative products, they are still very important. Therefore, it is still necessary to have a deep grasp of PowerDesigner The use of data modeling, this is the end of this article, thank you for watching.

Guess you like

Origin blog.csdn.net/zhangcongyi420/article/details/131501373