diff --git "a/29 \346\262\210\346\231\223\347\220\263/20230910 \344\275\234\344\270\232.md" "b/29 \346\262\210\346\231\223\347\220\263/20230910 \344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..6d222d7ecf0a194432947d919f810d180abc2bfc --- /dev/null +++ "b/29 \346\262\210\346\231\223\347\220\263/20230910 \344\275\234\344\270\232.md" @@ -0,0 +1,173 @@ +## 心得 + +1. 概念模型COM,ER图。 +2. 逻辑模型LDM,计算机。 +3. 物理模型PDM,从具体数据系角度 +4. 生成DDL + +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/10 23:25:52 */ +/*==============================================================*/ +CREATE DATABASE library charset utf8; +use library; + +drop table if exists b_type; + +drop table if exists book; + +drop table if exists borrow; + +drop table if exists class; + +drop table if exists reader; + +drop table if exists readertype; + +drop table if exists "return"; + +drop table if exists student; + +drop table if exists teacher; + +/*==============================================================*/ +/* Table: b_type */ +/*==============================================================*/ +create table b_type +( + t_id int not null auto_increment, + t_name varchar(10) not null, + t_decription varchar(20) not null, + primary key (t_id) +); + +/*==============================================================*/ +/* Table: book */ +/*==============================================================*/ +create table book +( + b_id int not null auto_increment, + t_id int not null, + author varchar(10) not null, + b_name varchar(20) not null, + publishing varchar(20) not null, + price int not null, + b_num int not null, + primary key (b_id) +); + +/*==============================================================*/ +/* Table: borrow */ +/*==============================================================*/ +create table borrow +( + b_id int not null, + r_id varchar(10) not null, + bor_time time not null, + bor_num int not null, + primary key (b_id, r_id) +); + +/*==============================================================*/ +/* Table: class */ +/*==============================================================*/ +create table class +( + c_id int not null auto_increment, + c_name varchar(10) not null, + c_num int not null, + primary key (c_id) +); + +/*==============================================================*/ +/* Table: reader */ +/*==============================================================*/ +create table reader +( + r_id varchar(10) not null, + rt_id int not null, + r_name varchar(5) not null, + state varchar(3) not null, + primary key (r_id) +); + +/*==============================================================*/ +/* Table: readertype */ +/*==============================================================*/ +create table readertype +( + rt_id int not null auto_increment, + rt_name char(2) not null, + b_quantity int not null, + b_time int not null, + primary key (rt_id) +); + +/*==============================================================*/ +/* Table: "return" */ +/*==============================================================*/ +create table "return" +( + r_id varchar(10) not null, + b_id int not null, + ret_time time not null, + ret_num int not null, + primary key (r_id, b_id) +); + +/*==============================================================*/ +/* Table: student */ +/*==============================================================*/ +create table student +( + s_id int not null auto_increment, + rt_id int not null, + c_id int not null, + s_sex char(1) not null, + s_name varchar(5) not null, + primary key (s_id) +); + +/*==============================================================*/ +/* Table: teacher */ +/*==============================================================*/ +create table teacher +( + te_id int not null auto_increment, + rt_id int, + te_name varchar(10) not null, + te_sex char(1) not null, + primary key (te_id) +); + +alter table book add constraint FK_classify foreign key (t_id) + references b_type (t_id) on delete restrict on update restrict; + +alter table borrow add constraint FK_borrow foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + +alter table borrow add constraint FK_borrow2 foreign key (r_id) + references reader (r_id) on delete restrict on update restrict; + +alter table reader add constraint FK_ׁ֟ؖ` foreign key (rt_id) + references readertype (rt_id) on delete restrict on update restrict; + +alter table "return" add constraint FK_return foreign key (r_id) + references reader (r_id) on delete restrict on update restrict; + +alter table "return" add constraint FK_return2 foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + +alter table student add constraint FK_Relationship_4 foreign key (rt_id) + references readertype (rt_id) on delete restrict on update restrict; + +alter table student add constraint FK_Relationship_6 foreign key (c_id) + references class (c_id) on delete restrict on update restrict; + +alter table teacher add constraint FK_Relationship_7 foreign key (rt_id) + references readertype (rt_id) on delete restrict on update restrict; + + +``` +