-
foreword
-
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.
-
Purpose
Assist logical model to database table structure.
-
Readers
Technical staff
-
the term
none
-
reference object
none
-
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.
-
Steps for usage
Open the data model with powerDesiner
-
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
-
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
-
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
-
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