diff --git "a/41 \345\221\250\344\272\232\350\276\211/20230914\345\214\273\347\224\237\357\274\214\347\227\205\344\272\272\344\270\216\350\215\257\345\223\201.md" "b/41 \345\221\250\344\272\232\350\276\211/20230914\345\214\273\347\224\237\357\274\214\347\227\205\344\272\272\344\270\216\350\215\257\345\223\201.md" new file mode 100644 index 0000000000000000000000000000000000000000..f6f09be6fdf09f216819299812d1694ce50df03e --- /dev/null +++ "b/41 \345\221\250\344\272\232\350\276\211/20230914\345\214\273\347\224\237\357\274\214\347\227\205\344\272\272\344\270\216\350\215\257\345\223\201.md" @@ -0,0 +1,105 @@ +## 笔记 + +如果一个主体的属性有多个值,那这个属性就可以拆成一个新主体 + +## 作业 + +医生,病人,药品制表 + +``` mysql + + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023-09-14 08:55:14 */ +/*==============================================================*/ + + +drop table if exists doctor; + +drop table if exists drug; + +drop table if exists medical; + +drop table if exists patients; + +drop table if exists prescription; + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doc_id int not null auto_increment, + doc_no varchar(20) not null, + doc_name varchar(10) not null, + doc_sex varchar(5), + primary key (doc_id) +); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug +( + dro_id int not null auto_increment, + dro_name varchar(20) not null, + primary key (dro_id) +); + +/*==============================================================*/ +/* Table: medical */ +/*==============================================================*/ +create table medical +( + ca_id int not null auto_increment, + doc_id int, + bat_no int, + date date, + diagnose varchar(50), + primary key (ca_id) +); + +/*==============================================================*/ +/* Table: patients */ +/*==============================================================*/ +create table patients +( + bat_no int not null auto_increment, + bat_name varchar(10) not null, + bat_age int, + bat_sex varchar(5), + primary key (bat_no) +); + +/*==============================================================*/ +/* Table: prescription */ +/*==============================================================*/ +create table prescription +( + dro_id int not null, + ca_id int not null, + bat_no int, + usa varchar(20), + dosage varchar(20), + primary key (dro_id, ca_id) +); + +alter table medical add constraint FK_Relationship_1 foreign key (doc_id) + references doctor (doc_id) on delete restrict on update restrict; + +alter table medical add constraint FK_Relationship_2 foreign key (bat_no) + references patients (bat_no) on delete restrict on update restrict; + +alter table prescription add constraint FK_Relationship_5 foreign key (bat_no) + references patients (bat_no) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription foreign key (dro_id) + references drug (dro_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription2 foreign key (ca_id) + references medical (ca_id) on delete restrict on update restrict; +``` + + +