Use powerDesigner logical model database structure initialization

  1. foreword

    1. background

     From the logical model to the database table structure, a series of operations are required. These operations are often used by architects, but ordinary programmers are often out of reach. This can assist programmers in role transformation.

  1. Purpose

  Assist logical model to database table structure.

  1. Readers

Technical staff

  1. the term

none

  1. reference object

none

  1. Application Scenario

  Architects generally build data models at a certain height based on business scenarios, and use logical models to be compatible with various relational databases.

  

  1. Steps for usage

    Open the data model with powerDesiner

  1. Logical model to physical model

    Select the logical model to be converted, and find Generat Physical Data Model in Tools in the menu bar.

 

 

 

 

Select your own database type and click OK. Be careful not to have invalid entity objects.

 

The result after conversion is as follows

 

  1. Physical model to database script

Select the generated physical model, and there is an additional Database item on the menu, click generate Database.

 

Modify the output path and modify the generated database sql file name

 

 

  1. Database script initialization

First, create the database userdb

 

Select the database, copy and paste the sql statement in userdb, open navicat, and execute after pasting.

 

Open the table on the left to see all generated tables

 

  1. Initialize base model fields

After the database is initialized, it is often necessary to add fields of the basic model to all tables, and batch processing is required at this time.

The first step is to generate batch-processing Sql statements

SELECT 

concat('alter table ',A.`TABLE_NAME` ,' add version_no int ;alter table ',A.`TABLE_NAME` ,' add 

created_by_cd varchar(32) ;alter table ',A.`TABLE_NAME` ,' add created_by_name varchar(100) ;alter 

table ',A.`TABLE_NAME` ,' add created_time datetime ;alter table ',A.`TABLE_NAME` ,' add 

last_updated_by_cd varchar(32) ;alter table ',A.`TABLE_NAME` ,' add last_updated_by_name varchar(100) 

;alter table ',A.`TABLE_NAME` ,' add last_updated_time datetime ;alter table ',A.`TABLE_NAME` ,' add 

deleted_flag bool default 0 ;')

FROM `information_schema`.`TABLES` A  

WHERE A.`TABLE_SCHEMA`='userdb'

 

The second step is to execute the statement

 

The execution results are as follows

 

Guess you like

Origin blog.csdn.net/zhb15810357012/article/details/131379883