From 7937f976952e701fb1d8076553a80644ae5324fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E4=BA=9A=E8=BE=89?= <3192667214@qq.com> Date: Thu, 14 Sep 2023 04:34:06 +0000 Subject: [PATCH] =?UTF-8?q?41=20=E5=91=A8=E4=BA=9A=E8=BE=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周亚辉 <3192667214@qq.com> --- ...72\344\270\216\350\215\257\345\223\201.md" | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "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" 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 0000000..f6f09be --- /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; +``` + + + -- Gitee