From 6fb8397b1b1229d2d297d0608eab267570a98d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=96=E5=BF=83=E5=A6=8D?= <2392642810@qq.com> Date: Sun, 10 Sep 2023 22:37:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\345\205\263\347\263\273.md" | 22 +-- .../20230908 powerdesigner.md" | 130 ++++++++++++++++++ 2 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 "03 \350\265\226\345\277\203\345\246\215/20230908 powerdesigner.md" diff --git "a/03 \350\265\226\345\277\203\345\246\215/20230906 \346\225\260\346\215\256\345\272\223\345\205\263\347\263\273.md" "b/03 \350\265\226\345\277\203\345\246\215/20230906 \346\225\260\346\215\256\345\272\223\345\205\263\347\263\273.md" index a3639c7..9d11a82 100644 --- "a/03 \350\265\226\345\277\203\345\246\215/20230906 \346\225\260\346\215\256\345\272\223\345\205\263\347\263\273.md" +++ "b/03 \350\265\226\345\277\203\345\246\215/20230906 \346\225\260\346\215\256\345\272\223\345\205\263\347\263\273.md" @@ -1,32 +1,22 @@ ## 数据库关系 -### 表与表的关系 +表与表:一对一、一对多、多对多 -#### 一对一(1、1) +### 一对一 例如:身份证与学生(任意放在一个表外键,此外键是另一个表的主键) -#### 一对多(1、N) +### 一对多 例如:教师与课程(一的主键放在多的外键) -#### 多对多(M、N) +### 多对多 例如:课程与学生(要引入第三张表,第三张表的外键要有前两张表的主键) -## E-R图 +### ER图 -#### 1.概念 - -E实体(表)、R关系(字段)、实体关系图,是指以实体、关系、属性三个基本概念概括数据的基本结构,从而描述静态数据结构的概念模式 - -#### 2.要素 - -实体、属性和关系 - -## 题目 - -以我们学院的组织框架,及学习课程来做系统,院系,专业,班级,学生,教师,课程,课程表,教室 +E实体(表)、R关系(字段)、实体关系图 ```mysql create database school charset utf8; diff --git "a/03 \350\265\226\345\277\203\345\246\215/20230908 powerdesigner.md" "b/03 \350\265\226\345\277\203\345\246\215/20230908 powerdesigner.md" new file mode 100644 index 0000000..5efb452 --- /dev/null +++ "b/03 \350\265\226\345\277\203\345\246\215/20230908 powerdesigner.md" @@ -0,0 +1,130 @@ +## powerdesigner + +第一步:创建概念模型图(CDM)以用户角度 + +第二步:转换逻辑模型图(LDM)以计算机角度 + +第三步:转换物理模型图(PDM)以数据角度 + +第四步:生成DDL + +表与表的关系:一个表里的几条记录对应另一个表的几条记录 + +数据库范式在实际中不会完全按照范式,根据需求实际操作 + +## 题目:图书管理系统 + +```mysql +create database lib charset utf8; + +use lib; + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/10 18:25:47 */ +/*==============================================================*/ + + +drop table if exists administrator; + +drop table if exists book; + +drop table if exists reader; + +drop table if exists stacks; + +drop table if exists system; + +drop table if exists type; + +/*==============================================================*/ +/* Table: administrator */ +/*==============================================================*/ +create table administrator +( + a_id char(10) not null, + a_name char(5) not null, + primary key (a_id) +); + +/*==============================================================*/ +/* Table: book */ +/*==============================================================*/ +create table book +( + b_id int not null auto_increment, + b_name varchar(10) not null, + author varchar(5) not null, + publication varchar(10) not null, + b_num int not null, + primary key (b_id) +); + +/*==============================================================*/ +/* Table: reader */ +/*==============================================================*/ +create table reader +( + r_id int not null auto_increment, + r_name char(5) not null, + r_sex char(1) not null, + r_age int not null, + primary key (r_id) +); + +/*==============================================================*/ +/* Table: stacks */ +/*==============================================================*/ +create table stacks +( + s_id int not null auto_increment, + b_id int not null, + s_name varchar(5) not null, + s_address varchar(5) not null, + primary key (s_id) +); + +/*==============================================================*/ +/* Table: system */ +/*==============================================================*/ +create table system +( + date_id int not null auto_increment, + b_id int not null, + r_id int not null, + a_id char(10) not null, + borrow date not null, + `return` date not null, + actual date, + primary key (date_id) +); + +/*==============================================================*/ +/* Table: type */ +/*==============================================================*/ +create table type +( + type_id int not null auto_increment, + b_id int not null, + type_name varchar(3) not null, + primary key (type_id) +); + +alter table stacks add constraint FK_deposit foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + +alter table system add constraint FK_Relationship_3 foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + +alter table system add constraint FK_Relationship_4 foreign key (r_id) + references reader (r_id) on delete restrict on update restrict; + +alter table system add constraint FK_manage foreign key (a_id) + references administrator (a_id) on delete restrict on update restrict; + +alter table type add constraint FK_categorize foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + + +``` + -- Gitee