MySQL-database design and implementation

Level 1: From conceptual model to MySQL implementation

mission details

Turn the established conceptual model into a physical implementation of MySQL.

related information

1. Phases of database design and tasks at each phase;
2. Conceptual model;
3. Logical model and its relationship with the conceptual model;
4. Physical implementation in DBMS.

Phases of database design and tasks for each phase

The design of the database is roughly divided into the following stages:
Requirements analysis
Determine the data (information) involved in the application system according to the business requirements, and process the requirements to form a data dictionary, including data knots, data structures, data streams, data storage, data
Conceptual structure design of documents such as processing process.
The main job is to model data. For relational database application systems, ER diagrams are mainly used to describe data and the relationship between data (of course, some people use UML class diagrams). There are two ways to express ER diagrams. One is Chen’s ER diagrams, which were first proposed by Peter Chen (professor at Louisiana State University) who was born in Kaohsiung, Taiwan. Textbooks mainly teach this kind of ER diagrams. Figure 1 uses Chen's ER diagram to express the conceptual model of the student course selection system commonly used in textbooks:

Conceptual model of student course selection

Figure 1 Students elective courses
Chen's ER diagram takes up a lot of space. When there are many entities and attributes in the system, the ovals (representing attributes) spreading from each rectangle representing entities will make the whole model appear confusing and crowded. So there was the later Crow's foot (crow's foot)-style ER diagram. Figure 2 uses the Crow's foot ER diagram to express the relationship between students and departments.

crow's foot

Figure 2 Crow's foot ER diagram
Figure 2 reflects the one-to-many relationship between departments and students, and the attributes of the two entities are listed below the respective entity names. Use a line with marks at both ends to connect two entities to express the connection between the two. The contact name is written in the middle of the line, which saves space. Please note that the shape of one-to-many connection is very similar to the crow's foot, hence the name Crow's foot (although the feet of most birds are like this).

Logic structure design
The main job is to convert the ER diagram into a relational model. There are rules for the transformation from conceptual structure to logical structure. It is related to the connection between two entities. The textbook has already talked about it enough. One advantage of the Crow's foot-style ER diagram is that it can be transformed into a logical structure by making a slight change to the original diagram (for example, directly adding the main code of one terminal to the multi-terminal), and then adding the main code, external code, index, and specifying Every type listed on a DBMS can quickly become a physical model, which is convenient for the computer to automatically create database objects. Figure 3 has given the data type of each attribute and defined the outer code.

pyiscal model

Figure 3 Crow's foot model close to physical mode

Physical structure design
The main work of physical structure design is to determine the storage structure and access methods on the basis of the logical structure, and to determine all data types for specific DBMSs.

Implementation and operation and maintenance
On the selected DBMS, create data objects, initialize data, test run, improve the system in the process of continuous debugging, and continue to improve and maintain.

Most modeling tools, such as ERWIN, Navicat, Microsoft Visio, Draw.IO, MySQL Workbench, etc., support Crows' foot. Visio and draw.io also support Chen's ER diagrams. Of the above tools, only Draw.IO and MySQL Workbench are free. ERWIN, Navicat and MySQL Workbench also support reverse engineering, that is, reverse engineering, based on the built database, reverse export model, but usually a physical model. Navicat supports continuous reverse to logical model and conceptual model. Basically, on the basis of reverse engineering, replace the specific data type of DMBS, such as changing varchar(50) to string, it is a logical model, remove all the outer code columns in the logical model, it becomes a conceptual model, Conceptual models may not annotate data types. However, in the production environment, software is often used to express models. In fact, common data types such as string, integer, float, datetime, boolean, etc. have been marked from the conceptual model.

programming requirements

The task of this level is to complete the implementation of MySQL according to a built logical model. The logical ER diagram is shown in Figure 3.

ER diagram of booking system

Figure 3 ER diagram of the conceptual model of the air ticket booking system
Explanation: This picture was drawn with draw.io, and it can be called out by entering draw.io in the address bar of the browser without installing any software.

Application background introduction

This is an air ticket booking system. The system needs to consider the following entities:
1. User (user)
There are two types of users. Ordinary users can book tickets, and administrative users have the authority to maintain and manage the operation of the entire system. For the sake of simplicity, the two types of users are merged and distinguished by the admin_tag tag. User attributes (including business constraints) are:
user ID: user_id int primary code, auto-increment
first name: firstname varchar(50) cannot be empty
last name: lastname varchar(50) cannot be empty
birthday: dob date cannot be empty
gender: sex char(1) Cannot be empty E-
mail: email varchar(50)
Contact number: phone varchar(30)
User name: username varchar(20) Cannot be empty, cannot be repeated
Password: password char(32) Cannot be
emptyAdministrator flag: admin_tag tinyint default value 0 (non-administrator), can not be empty

2. Passenger
users log in to the system not necessarily to buy tickets for themselves, so user and passenger information are stored separately. Attributes include:
Passenger number: passenger_id int auto-increment, main code
Document number: id char(18) Cannot be empty or repeated First name
: firstname varchar(50) Can not be empty
Last name: lastname varchar(50) Can not be empty
Email: mail varchar(50)
phone: phone varchar(20) not nullable
sex: sex char(1) not nullable
birthday: dob date

3. The airport (airport)
has the following attributes:
number: airport_id int auto-increment, main code
ICAO code: iata char(3) not empty, unique in the world
IATA code: icao char(4) not empty, unique
airport in the world Name: name varchar(50) Cannot be empty, common index
City: city varchar(50)
Country: country varchar(50)
Latitude: latitude decimal(11,8)
Longitude: longitude decimal(11,8)
Every airport in the world There are unique IATA codes and ICAO codes, IATA is 3 characters, and ICAO is 4 characters. For example, (IATA, ICAO) of Capital Airport is (PEK, ZBAA), Daxing Airport is (PKX, ZBAD), and Tianhe Airport is (WUH, ZHHH). Both the place of departure and the place of arrival are indicated by IATA on the aircraft registration plate. In order to display the airport location on the map, it is necessary to record the latitude and longitude information.

4. The airline (airline)
has the following attributes:
number: airline_id int auto-increment, main code
name: name varchar(30) non-nullable
ICAO code: iata char(2) non-nullable, the IATA of the globally unique
airline The code is 2 digits, such as MU for China Eastern Airlines, CA for Air China, CZ for China Southern Airlines, etc. The flight number is generally prefixed with the IATA code of the airline to which it belongs.

5. Civil aviation aircraft (airplane)
has attributes:
number: airplane_id int self-incrementing, main code
type: type varchar(50) cannot be empty, such as B737-300, A320-500, etc.
Seat: capacity smallint cannot be empty
ID: identifier varchar( 50) Non-nullable

6. Regular flight schedule (flightschedule)
The flights are generally arranged on a weekly basis, for example: two flights per week, Monday and Friday.
Has attributes:
flight number: flight_no char(8) master code
departure time: departure time is not empty
arrival time: arrival time is not empty
flight duration: duration smalint is not empty
Monday: monday tinyint default 0
Tuesday: tuesday tinyint default 0
Wednesday: wednesday tinyint Default 0
Thursday: thursday tinyint Default 0
Friday: friday tinyint Default 0
Saturday: saturday tinyint Default 0
Sunday: sunday tinyint Default 0
The flight duration is generally measured in minutes.

7. Flight schedule (flight)
Flights are arranged based on the regular schedule of flights. However, the schedule is not static, and not every scheduled flight actually takes off, nor does it always take off at the scheduled time, so the actual flight must be arranged and recorded separately.
The information to be recorded is:
flight number: flight_id int auto-increment, master code
Departure time: departure datetime is not empty
Arrival time: arrival datetime is not empty
Flight duration: duration smallint is not
empty Some systems will also display the flight latitude and longitude and altitude position in real time, Here we simplified and removed the real-time flight information.

8. Air ticket (ticket)
Users can buy air tickets for a certain flight for themselves or their relatives and friends. The attributes of the ticket are:
ticket number: ticket_id int self-incrementing, main code
seat number: seat char(4)
price: price decimal(10,2) cannot be empty

9. The connection between entities
The connection between entities is clearly marked in the ER diagram:

  • Each airline has a home port (airport), also called a base. A large airport may be the base of several companies, and a small airport may not be the base of any airline.
  • Each flight belongs to an airline, and an airline can have many flights.
  • Any civil aviation aircraft belongs to an airline, and the airline can have more than one aircraft.
  • Each aircraft can fly multiple flights, and one flight is operated by one aircraft.
  • A flight can sell several tickets according to the aircraft type. A ticket is a ticket for a particular flight.
  • Users can book tickets multiple times, and passengers can take planes multiple times. A ticket must be a ticket for a specific flight purchased by a user for a specific passenger. That is, the ticket information is not only related to the passenger, but also records the purchaser information (although the two are sometimes the same person). For simplicity, ordering time is not considered.
  • Whether it is a regular planned flight or an actual flight, it departs from one airport and arrives at another. But an airport can be the origin of many flights and the destination of many flights.

Based on the above information and the given ER diagram, please give the statement to implement flight_booking in MySQL, including building database, creating table, creating primary key, external key, index, specifying default, and constraints such as not being empty. All indexes use BTREE. The names of all constraints are not required. All outer codes have the same name as the main code. There are two exceptions: both scheduled and flown flights involve departure airports and arrival airports, and the outer key has the same name as the main key, resulting in two columns with the same name in the same table. Therefore, these two outer codes are handled as exceptions: the departure airport is named from, and the arrival airport is named to.
Note: All table names and column names do not have capital letters. The column name has the same name as the keyword, please handle it properly. You may not pass the evaluation once, please consider the situation where your code needs to be modified and re-run repeatedly.

If you think the above picture is not clear enough, you can go to:
https://gitee.com/kylin8575543/db2022-spring
Click to download the data package required for training, or you can directly view this document:
https://gitee.com/kylin8575543/ db2022-spring/blob/master/flightbooking.png

Please fill in the statement in the code file on the right, and then submit for evaluation.

Test instruction

The evaluation program will execute your code file, and then check whether all database objects are completely consistent with the expected results (the names of all constraints, including primary key, foreign code, default, and unique are not included in the evaluation).


Let's start your mission, I wish you success!

Reference Code

 # 请将你实现flight_booking数据库的语句写在下方:
 
drop database if exists flight_booking; 
create database flight_booking; 
use flight_booking;
 
SET NAMES utf8mb4; 
SET FOREIGN_KEY_CHECKS = 0;
 
DROP TABLE IF EXISTS airline ; CREATE TABLE airline ( airline_id int NOT NULL AUTO_INCREMENT, name varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, iata char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, airport_id int NOT NULL, PRIMARY KEY ( airline_id ) USING BTREE, UNIQUE INDEX iata_unq ( iata ) USING BTREE, INDEX base_airport_idx ( airport_id ) USING BTREE, CONSTRAINT airline_ibfk_1 FOREIGN KEY ( airport_id ) REFERENCES airport ( airport_id ) ON DELETE RESTRICT ON UPDATE RESTRICT ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
DROP TABLE IF EXISTS airplane ; CREATE TABLE airplane ( airplane_id int(0) NOT NULL AUTO_INCREMENT, type varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, capacity smallint(0) NOT NULL, identifier varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, airline_id int(0) NOT NULL,
PRIMARY KEY ( airplane_id ) USING BTREE, INDEX airplane_ibfk_1 ( airline_id ) USING BTREE, CONSTRAINT airplane_ibfk_1 FOREIGN KEY ( airline_id ) REFERENCES airline ( airline_id ) ON DELETE RESTRICT ON UPDATE RESTRICT ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
DROP TABLE IF EXISTS airport ; CREATE TABLE airport ( airport_id int NOT NULL AUTO_INCREMENT, iata char(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, icao char(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, name varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, city varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, country varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, latitude decimal(11, 8) NULL DEFAULT NULL, longitude decimal(11, 8) NULL DEFAULT NULL, PRIMARY KEY ( airport_id ) USING BTREE, UNIQUE INDEX iata_unq ( iata ) USING BTREE, UNIQUE INDEX icao_unq ( icao ) USING BTREE, INDEX name_idx ( name ) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 
DROP TABLE IF EXISTS passenger ; CREATE TABLE passenger ( passenger_id int NOT NULL AUTO_INCREMENT, id char(18) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, firstname varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, lastname varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, mail varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, phone varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, sex char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, dob date NULL DEFAULT NULL, PRIMARY KEY ( passenger_id ) USING BTREE, UNIQUE INDEX id_unq ( id ) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 
DROP TABLE IF EXISTS ticket ; CREATE TABLE ticket ( ticket_id int NOT NULL AUTO_INCREMENT, flight_id int NOT NULL, seat char(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, passenger_id int NOT NULL, price decimal(10, 2) NOT NULL, user_id int NOT NULL, PRIMARY KEY ( ticket_id ) USING BTREE, INDEX flight_idx ( flight_id ) USING BTREE, INDEX passenger_idx ( passenger_id ) USING BTREE, INDEX ticket_ibfk_3 ( user_id ) USING BTREE, CONSTRAINT ticket_ibfk_1 FOREIGN KEY ( flight_id ) REFERENCES flight ( flight_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT ticket_ibfk_2 FOREIGN KEY ( passenger_id ) REFERENCES passenger ( passenger_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT ticket_ibfk_3 FOREIGN KEY ( user_id ) REFERENCES user ( user_id ) ON DELETE RESTRICT ON UPDATE RESTRICT ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 
 
DROP TABLE IF EXISTS user ; CREATE TABLE user ( user_id int NOT NULL AUTO_INCREMENT, firstname varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, lastname varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, dob date NOT NULL, sex char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, email varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
phone varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, username varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, password char(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, admin_tag tinyint NOT NULL DEFAULT 0, PRIMARY KEY ( user_id ) USING BTREE, UNIQUE INDEX user_unq ( username ) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;
 
 
DROP TABLE IF EXISTS flightschedule ; CREATE TABLE flightschedule ( flight_no char(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `from` int NOT NULL, `to` int NOT NULL, departure time NOT NULL, arrival time NOT NULL, duration smallint NOT NULL,
airline_id int NOT NULL, monday tinyint NULL DEFAULT 0, 
tuesday tinyint NULL DEFAULT 0, 
wednesday tinyint NULL DEFAULT 0, 
thursday tinyint NULL DEFAULT 0, friday tinyint NULL DEFAULT 0, saturday tinyint NULL DEFAULT 0, sunday tinyint NULL DEFAULT 0, 
PRIMARY KEY ( flight_no ) USING BTREE, 
INDEX from_idx ( `from` ) USING BTREE, 
INDEX to_idx ( `to` ) USING BTREE, 
INDEX airline_idx ( airline_id ) USING BTREE, 
CONSTRAINT flightschedule_ibfk_1 FOREIGN KEY ( `from` ) REFERENCES airport ( airport_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT flightschedule_ibfk_2 FOREIGN KEY ( `to` ) REFERENCES airport ( airport_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT flightschedule_ibfk_3 FOREIGN KEY ( airline_id ) REFERENCES airline ( airline_id ) ON DELETE RESTRICT ON UPDATE RESTRICT ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
DROP TABLE IF EXISTS flight ; CREATE TABLE flight ( flight_id int NOT NULL AUTO_INCREMENT, flight_no char(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `from` int NOT NULL, `to` int NOT NULL,
departure datetime NOT NULL, arrival datetime NOT NULL, duration smallint NOT NULL, airline_id int NOT NULL, airplane_id int NOT NULL, 
PRIMARY KEY ( flight_id ) USING BTREE, 
INDEX from_idx ( `from` ) USING BTREE, 
INDEX to_idx ( `to` ) USING BTREE, 
-- INDEX departure_idx ( departure ) USING BTREE, 
-- INDEX arrivals_idx ( arrival ) USING BTREE, 
INDEX airline_idx ( airline_id ) USING BTREE, 
INDEX airplane_idx ( airplane_id ) USING BTREE, 
INDEX flightno ( flight_no ) USING BTREE, 
CONSTRAINT flight_ibfk_1 FOREIGN KEY ( `from` ) REFERENCES airport ( airport_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT flight_ibfk_2 FOREIGN KEY ( `to` ) REFERENCES airport ( airport_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT flight_ibfk_3 FOREIGN KEY ( airline_id ) REFERENCES airline ( airline_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT flight_ibfk_4 FOREIGN KEY ( airplane_id ) REFERENCES airplane ( airplane_id ) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT flight_ibfk_5 FOREIGN KEY ( flight_no ) REFERENCES flightschedule ( flight_no ) ON DELETE RESTRICT ON UPDATE RESTRICT ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 
SET FOREIGN_KEY_CHECKS = 1;

Level 2: From requirements analysis to logical model

mission details

The task of this level:
According to the description of the business requirements of the application scenario, complete the ER diagram and convert it into a relational model.
Submit design documents

Business function description

Design a theater management system. The cinema arranges the current screening hall and movies. After customers arrive, they can buy movie tickets for any scene and enter the corresponding screening hall to watch. The system has the following entity sets:

  1. Movie (movie): attributes include identification number (movie_ID), movie name (title), type (type), duration (runtime), premiere date (release_date), director name (director), and starring name (starring).
  2. Customer (customer): The attributes include identification number (c_ID), name (name), and mobile phone number (phone).
  3. Auditorium (hall): The attributes include identification number (hall_ID), projection mode (mode), capacity, and location.
  4. Schedule (schedule): The attributes include identification number (schedule_ID), date (date), time (time), ticket price (price), and number of votes (number).
  5. Movie ticket (ticket): attributes include identification number (ticket_ID) and seat number (seat_num). The relationship between entities is described as follows: ①. There is a one-to-many purchase relationship between customers and movie tickets. Each customer can buy multiple movie tickets, and each movie ticket is purchased by one customer. ②. There is a many-to-one relationship between movie tickets and scenes. A movie ticket belongs to only one scene, and a scene has multiple movie tickets. ③. There is a one-to-many relationship between ostentation and movies. One film is shown in each scene, and each film can be shown in multiple scenes. ④. The scene and the auditorium have a one-to-many relationship. Each scene is located in one projection hall, and each projection hall can arrange multiple scenes.

mission requirements

  1. Draw the ER diagram according to the above requirements.
  2. Give the corresponding relation schema.

If modeling with modeling tools, please save the model as a picture, if drawing manually, please take a photo, sign the picture, or add an electronic signature. Please name the image file as ersolution.jpg. And upload the image file to the Internet (such as your open source project on github or gitee, or any place that can be directly accessed). Fill in the URL to access the picture in the second line of the editor on the right. The URL should directly locate the picture (instead of finding the picture in a certain web page), that is, click the URL to open the picture directly.

Then, write out the relational schema in a file editor.
The expression format of the relationship model refers to:
student (student number, name, gender, date of birth, department id), main code: (student number); outer code: (department id)
do not use pure Chinese symbols.

Test instruction

The evaluation program will check whether you have submitted the document. Due to the multi-solution nature of the design, the evaluation program cannot give a specific score. As long as the document is submitted and the relationship model is given, the score will be assigned first. After the manual review, according to your completion, a certain point value will be deducted from the total score (or not deducted) as appropriate.


Let's start your mission, I wish you success!

code reference

 请给出ER图文件存放的URL:
https://free.wzznft.com/i/2023/05/18/ersolution.jpg
 以下给出关系模式:

电影(movie)(movie_ID, title, type, runtime, release_date, director, starring), 主码:(movie_ID)

顾客(customer)(c_ID, name, phone), 主码:(c_ID)

放映厅(hall)(hall_ID, mode, capacity, location), 主码:(hall_ID)

排场(schedule)(schedule_ID, date, time, price, number, hall_ID, movie_ID), 主码:(schedule_ID),外码:(hall_ID) 参照放映厅(hall)(movie_ID) 参照电影(movie)

电影票(ticket)(ticket_ID, seat_num, c_ID, schedule_ID), 主码:(ticket_ID),外码:(c_ID) 参照顾客(customer)(schedule_ID) 参照排场(schedule)

picture backup
ER图

Level 3: Use of modeling tools

mission details

The task of this level:
automatically convert a built model file into a SQL script by using the forward engineering function of MySQL Workbench.

related information

In order to complete this task, you need to master:
1. Commonly used modeling tools and their characteristics;
2. Learn to use tools for modeling;
3. Forward Engineering and Reverse Engineering.

Introduction to Modeling Tools

1. ERWIN
erwin Data Modeler industry-leading data modeling solution, with intuitive design and archiving functions, supports the management of any data in any storage location throughout the enterprise. But the fee is more expensive, but college students can apply for erwin Data Modeler Academic Edition, which is valid for 1 year. You can go to the official website to download documents to understand the specific functions and usage methods:
Chinese official website: http://www.erwinchina.com/

2. Navicat
Navicat supports almost all of your commonly used DBMS, supports conceptual models, logical models and physical models, and can generate scripts for any DBMS based on model files. Support Forward Engineering and Reverse Engineering.
The software is also free.
Navicat is also a DBMS client management tool with many users.
Chinese official website:
https://www.navicat.com.cn/

3.Microsoft Visio

Now, Visio has been separated from Office and needs to be purchased separately. Support Chen's ER diagram and Crow's foot. It can be used to express conceptual models, logical models, etc.

4.Draw.io
is the easiest modeling tool to obtain. You only need to enter the URL in the address bar of the web browser to call up:
draw.io
or:
https://app.diagrams.net/
Enter the former and it will automatically jump Go to the latter.
It is more suitable for establishing conceptual models and logical models. Both Chen's ER diagram and Crow's feet ER diagram are supported. But it cannot be connected with specific DBMS, and does not support forward and reverse engineering.

5. MySQL Workbench
is a free tool that comes with the MySQL Community Edition. It is also a relatively easy-to-use graphical interface client management tool. Supports forward and reverse tools.
The user manual can be downloaded from the official website.

programming requirements

Go to
https://gitee.com/kylin8575543/db2022-spring
to download the data package required for training, or just download this file:
https://gitee.com/kylin8575543/db2022-spring/raw/master/rbac.mwb

This is a model file rbac.mwb that has been built. Please use the Forward engineering function in the MySQL Workbench modeling module to automatically export SQL scripts.

Forward Engineering

After offline processing, please paste the script into the code file.

Test instruction

The profiler will execute your code file and check that all database objects are exactly as expected. You don't need to modify the scripts exported by Workbench.


Let's start your mission, I wish you success!

code reference

 # 请将利用MySQL Workbench软件的Modeling工具,经forward engineering 导出的创建schema的SQL语句完整粘到此处:
 
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 
SET @OLD_SQL_MODE=@@SQL_MODE, 
SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
 
CREATE SCHEMA IF NOT EXISTS rbac DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ; 
USE rbac ;
 
 
CREATE TABLE IF NOT EXISTS rbac . aprole (
RoleNo INT NOT NULL COMMENT '角色编号', 
RoleName CHAR(20) NOT NULL COMMENT '角色名', 
Comment VARCHAR(50) NULL DEFAULT NULL COMMENT '角色描述', 
Status SMALLINT NULL DEFAULT NULL COMMENT '角色状态', 
PRIMARY KEY ( RoleNo )) 
ENGINE = InnoDB 
DEFAULT CHARACTER SET = utf8mb4 
COLLATE = utf8mb4_0900_ai_ci 
COMMENT = '角色表';
 
CREATE TABLE IF NOT EXISTS rbac . apuser(
    UserID CHAR(8) NOT NULL COMMENT '用户工号',
    UserName CHAR(8) NULL DEFAULT NULL COMMENT '用户姓名', 
    Comment VARCHAR(50) NULL DEFAULT NULL COMMENT '用户描述', 
    PassWord CHAR(32) NULL DEFAULT NULL COMMENT '口令', 
    Status SMALLINT NULL DEFAULT NULL COMMENT '状态',
    PRIMARY KEY ( UserID ), 
    UNIQUE INDEX ind_username ( UserName ASC) VISIBLE) 
    ENGINE = InnoDB 
    DEFAULT CHARACTER SET = utf8mb4
    COLLATE = utf8mb4_0900_ai_ci 
    COMMENT = '用户表';
 
CREATE TABLE IF NOT EXISTS rbac . apgroup (
    UserID CHAR(8) NOT NULL COMMENT '用户编号', 
    RoleNo INT NOT NULL COMMENT '角色编号', 
    PRIMARY KEY ( UserID , RoleNo ), 
    INDEX FK_apGroup_apRole ( RoleNo ASC) VISIBLE, 
    CONSTRAINT FK_apGroup_apRole FOREIGN KEY ( RoleNo ) REFERENCES rbac . aprole ( RoleNo ),
    CONSTRAINT FK_apGroup_apUser FOREIGN KEY ( UserID ) REFERENCES rbac . apuser ( UserID ))
    ENGINE = InnoDB 
    DEFAULT CHARACTER SET = utf8mb4 
    COLLATE = utf8mb4_0900_ai_ci 
    COMMENT = '角色分配表';
 
CREATE TABLE IF NOT EXISTS rbac . apmodule (
    ModNo BIGINT NOT NULL COMMENT '模块编号', 
    ModID CHAR(10) NULL DEFAULT NULL COMMENT '系统或模块的代码', 
    ModName CHAR(20) NULL DEFAULT NULL COMMENT '系统或模块的名称', PRIMARY KEY ( ModNo ))
    ENGINE = InnoDB 
    DEFAULT CHARACTER SET = utf8mb4 
    COLLATE = utf8mb4_0900_ai_ci 
    COMMENT = '功能模块登记表';
 
CREATE TABLE IF NOT EXISTS rbac . apright (
RoleNo INT NOT NULL COMMENT '角色编号', 
ModNo BIGINT NOT NULL COMMENT '模块编号', 
PRIMARY KEY ( RoleNo , ModNo ), 
INDEX FK_apRight_apModule ( ModNo ASC) VISIBLE,
CONSTRAINT FK_apRight_apModule 
FOREIGN KEY ( ModNo ) 
REFERENCES rbac . apmodule ( ModNo ), 
CONSTRAINT FK_apRight_apRole
FOREIGN KEY ( RoleNo ) 
REFERENCES rbac . aprole ( RoleNo ))
ENGINE = InnoDB 
DEFAULT CHARACTER SET = utf8mb4 
COLLATE = utf8mb4_0900_ai_ci 
COMMENT = '角色权限表';
 
SET SQL_MODE=@OLD_SQL_MODE; 
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; 
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

Guess you like

Origin blog.csdn.net/qq_46373141/article/details/130745049