diff --git "a/06 \351\231\210\345\277\227\344\274\237/20230908.md" "b/06 \351\231\210\345\277\227\344\274\237/20230908.md" new file mode 100644 index 0000000000000000000000000000000000000000..5bfc1e28c176af08beda8c4ee00521964ab875b6 --- /dev/null +++ "b/06 \351\231\210\345\277\227\344\274\237/20230908.md" @@ -0,0 +1,145 @@ +## 笔记 + +PowerDesigner制作ER图可以转换成数据库形式,操作形式如下: + +第一步:创建概念模型(类似ER图) CDM 以用户角度 + +第二步:转换成逻辑模型 LDM 以计算机角度 + +第三步:转换成物理 PDM 以数据角度 + +第四步:生成DDL + +## ER图 + +![8750562da5843903a5aeabd6c0b120d](https://s2.loli.net/2023/09/11/PlZvLfmqhsAMuyw.png) + +## sql代码 + +```sql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/11 20:20:24 */ +/*==============================================================*/ +CREATE DATABASE bookes charset utf8; +use bookes; + +drop table if exists book; + +drop table if exists guanli; + +drop table if exists jie; + +drop table if exists librarian; + +drop table if exists library; + +drop table if exists reader; + +drop table if exists system; + +/*==============================================================*/ +/* Table: book */ +/*==============================================================*/ +create table book +( + bo_id char(10) not null, + sys_id int not null, + bo_name char(10) not null, + bo_author char(10) not null, + primary key (bo_id) +); + +/*==============================================================*/ +/* Table: guanli */ +/*==============================================================*/ +create table guanli +( + sys_id int not null, + rar_id int not null, + primary key (sys_id, rar_id) +); + +/*==============================================================*/ +/* Table: jie */ +/*==============================================================*/ +create table jie +( + bo_id char(10) not null, + re_id int not null, + rar_id int, + primary key (bo_id, re_id) +); + +/*==============================================================*/ +/* Table: librarian */ +/*==============================================================*/ +create table librarian +( + rar_id int not null auto_increment, + lib_id int not null, + rar_name varchar(20) not null, + rar_sex varchar(1) not null, + rar_age int not null, + primary key (rar_id) +); + +/*==============================================================*/ +/* Table: library */ +/*==============================================================*/ +create table library +( + lib_id int not null auto_increment, + lib_name varchar(10) not null, + lib_add varchar(100) not null, + primary key (lib_id) +); + +/*==============================================================*/ +/* Table: reader */ +/*==============================================================*/ +create table reader +( + re_id int not null auto_increment, + re_name varchar(5) not null, + re_age int not null, + re_tel numeric(11,0) not null, + primary key (re_id) +); + +/*==============================================================*/ +/* Table: system */ +/*==============================================================*/ +create table system +( + sys_id int not null auto_increment, + sys_mian decimal(4,1) not null, + sys_add varchar(100) not null, + sys_tel numeric(11,0) not null, + primary key (sys_id) +); + +alter table book add constraint FK_lay foreign key (sys_id) + references system (sys_id) on delete restrict on update restrict; + +alter table guanli add constraint FK_guanli foreign key (sys_id) + references system (sys_id) on delete restrict on update restrict; + +alter table guanli add constraint FK_guanli2 foreign key (rar_id) + references librarian (rar_id) on delete restrict on update restrict; + +alter table jie add constraint FK_jie foreign key (bo_id) + references book (bo_id) on delete restrict on update restrict; + +alter table jie add constraint FK_jie2 foreign key (re_id) + references reader (re_id) on delete restrict on update restrict; + +alter table jie add constraint FK_mate foreign key (rar_id) + references librarian (rar_id) on delete restrict on update restrict; + +alter table librarian add constraint FK_manage foreign key (lib_id) + references library (lib_id) on delete restrict on update restrict; + + +``` +