From 53a964aee4e99a2be75781b81f80ada91817fc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=81=E6=B6=9B?= <1841582040@qq.com> Date: Thu, 14 Sep 2023 01:04:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...42\346\225\260\346\215\256\345\272\223.md" | 201 ++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 "57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" diff --git "a/57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" "b/57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000..c5e8185 --- /dev/null +++ "b/57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,201 @@ +# 笔记 + +#### 如果一个主体的属性有多个值,那这个属性就可以拆成一个新主体 + +# 作业 + +### 医院数据库设计 + + 需求分析 + +科室(科室编号,科室名,地址,联系电话) + +病人(病历号,姓名,年龄,性别) + +病房(病房编号,病房名) + +药品(药品编号,药品名称,价格,重量) + +药品分类(分类编号,分类名) + +药房 (药房编号,药房名) + +护士(工号,姓名,年龄,性别) + +![image-20230914004615604](https://s2.loli.net/2023/09/14/z5mAUwqBgyjKXIx.png) + +![image-20230914005035168](https://s2.loli.net/2023/09/14/1T5rtYRc4SHB8WG.png) + +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/14 0:41:52 */ +/*==============================================================*/ +create DATABASE yy charset utf8; +use yy; + +drop table if exists assignment; + +drop table if exists department; + +drop table if exists doctor; + +drop table if exists nurse; + +drop table if exists patient; + +drop table if exists pharmaceuticals; + +drop table if exists pharmacy; + +drop table if exists prescription; + +drop table if exists type; + +drop table if exists ward; + +/*==============================================================*/ +/* Table: assignment */ +/*==============================================================*/ +create table assignment +( + ward_id int not null, + nurse_id char(10) not null, + primary key (ward_id, nurse_id) +); + +/*==============================================================*/ +/* Table: department */ +/*==============================================================*/ +create table department +( + departmen_id int not null auto_increment, + department_name varchar(10) not null, + department_add varchar(50) not null, + department_tel char(11) not null, + primary key (departmen_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doctor_id char(10) not null, + departmen_id int not null, + doctor_name varchar(4) not null, + doctor_age char(2) not null, + doctor_sex char(1) not null, + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: nurse */ +/*==============================================================*/ +create table nurse +( + nurse_id char(10) not null, + nurse_name varchar(4) not null, + nurse_age char(2) not null, + nurse_sex char(1) not null, + primary key (nurse_id) +); + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient +( + patient_id char(10) not null, + doctor_id char(10) not null, + ward_id int not null, + patient_name varchar(4) not null, + patient_age char(2) not null, + patient_sex char(1) not null, + primary key (patient_id) +); + +/*==============================================================*/ +/* Table: pharmaceuticals */ +/*==============================================================*/ +create table pharmaceuticals +( + pharmaceuticals_id int not null auto_increment, + pharmacy_id int not null, + type_id int not null, + pharmaceuticals_name varchar(10) not null, + pharmaceuticals_prrice int not null, + pharmaceuticals_wigat decimal(5,2) not null, + primary key (pharmaceuticals_id) +); + +/*==============================================================*/ +/* Table: pharmacy */ +/*==============================================================*/ +create table pharmacy +( + pharmacy_id int not null auto_increment, + pharmacy_name varchar(10) not null, + primary key (pharmacy_id) +); + +/*==============================================================*/ +/* Table: prescription */ +/*==============================================================*/ +create table prescription +( + pharmaceuticals_id int not null, + patient_id char(10) not null, + primary key (pharmaceuticals_id, patient_id) +); + +/*==============================================================*/ +/* Table: type */ +/*==============================================================*/ +create table type +( + type_id int not null auto_increment, + type_name varchar(3) not null, + primary key (type_id) +); + +/*==============================================================*/ +/* Table: ward */ +/*==============================================================*/ +create table ward +( + ward_id int not null auto_increment, + ward_name varchar(10) not null, + primary key (ward_id) +); + +alter table assignment add constraint FK_assignment foreign key (ward_id) + references ward (ward_id) on delete restrict on update restrict; + +alter table assignment add constraint FK_assignment2 foreign key (nurse_id) + references nurse (nurse_id) on delete restrict on update restrict; + +alter table doctor add constraint FK_belong foreign key (departmen_id) + references department (departmen_id) on delete restrict on update restrict; + +alter table patient add constraint FK_diagnosis foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table patient add constraint FK_live foreign key (ward_id) + references ward (ward_id) on delete restrict on update restrict; + +alter table pharmaceuticals add constraint FK_deposit foreign key (pharmacy_id) + references pharmacy (pharmacy_id) on delete restrict on update restrict; + +alter table pharmaceuticals add constraint FK_have foreign key (type_id) + references type (type_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription foreign key (pharmaceuticals_id) + references pharmaceuticals (pharmaceuticals_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription2 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + + +``` + -- Gitee From 5128b6a707bb2af98e370337cf8d4266384b3d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=81=E6=B6=9B?= <1841582040@qq.com> Date: Thu, 14 Sep 2023 02:00:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...42\346\225\260\346\215\256\345\272\223.md" | 73 ++++++++++++++++--- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git "a/57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" "b/57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" index c5e8185..23aa046 100644 --- "a/57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" +++ "b/57 \351\273\204\346\265\201\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" @@ -22,22 +22,24 @@ 护士(工号,姓名,年龄,性别) -![image-20230914004615604](https://s2.loli.net/2023/09/14/z5mAUwqBgyjKXIx.png) +![image-20230914011846375](https://s2.loli.net/2023/09/14/JgjkF7sh3MxXiqW.png) -![image-20230914005035168](https://s2.loli.net/2023/09/14/1T5rtYRc4SHB8WG.png) +![image-20230914012312885](https://s2.loli.net/2023/09/14/X89l3YLiEfydJcx.png) ```mysql /*==============================================================*/ /* DBMS name: MySQL 5.0 */ -/* Created on: 2023/9/14 0:41:52 */ +/* Created on: 2023/9/14 1:24:04 */ /*==============================================================*/ -create DATABASE yy charset utf8; +create database yy charset utf8; use yy; drop table if exists assignment; drop table if exists department; +drop table if exists diagnosis; + drop table if exists doctor; drop table if exists nurse; @@ -61,6 +63,7 @@ create table assignment ( ward_id int not null, nurse_id char(10) not null, + assignment_date date not null, primary key (ward_id, nurse_id) ); @@ -76,6 +79,18 @@ create table department primary key (departmen_id) ); +/*==============================================================*/ +/* Table: diagnosis */ +/*==============================================================*/ +create table diagnosis +( + patient_id char(10) not null, + doctor_id char(10) not null, + diagnosis_name varchar(255) not null, + diagnosis_time datetime not null, + primary key (patient_id, doctor_id) +); + /*==============================================================*/ /* Table: doctor */ /*==============================================================*/ @@ -95,6 +110,7 @@ create table doctor create table nurse ( nurse_id char(10) not null, + departmen_id int not null, nurse_name varchar(4) not null, nurse_age char(2) not null, nurse_sex char(1) not null, @@ -107,7 +123,6 @@ create table nurse create table patient ( patient_id char(10) not null, - doctor_id char(10) not null, ward_id int not null, patient_name varchar(4) not null, patient_age char(2) not null, @@ -146,6 +161,8 @@ create table prescription ( pharmaceuticals_id int not null, patient_id char(10) not null, + prescription_say varchar(255) not null, + prescription_time time not null, primary key (pharmaceuticals_id, patient_id) ); @@ -175,11 +192,17 @@ alter table assignment add constraint FK_assignment foreign key (ward_id) alter table assignment add constraint FK_assignment2 foreign key (nurse_id) references nurse (nurse_id) on delete restrict on update restrict; +alter table diagnosis add constraint FK_diagnosis foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table diagnosis add constraint FK_diagnosis2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + alter table doctor add constraint FK_belong foreign key (departmen_id) references department (departmen_id) on delete restrict on update restrict; -alter table patient add constraint FK_diagnosis foreign key (doctor_id) - references doctor (doctor_id) on delete restrict on update restrict; +alter table nurse add constraint FK_belongs foreign key (departmen_id) + references department (departmen_id) on delete restrict on update restrict; alter table patient add constraint FK_live foreign key (ward_id) references ward (ward_id) on delete restrict on update restrict; @@ -195,7 +218,39 @@ alter table prescription add constraint FK_prescription foreign key (pharmaceuti alter table prescription add constraint FK_prescription2 foreign key (patient_id) references patient (patient_id) on delete restrict on update restrict; - - + +#科室 +insert into department values +(1,"内科","2楼","12345678912"),(2,"外科","5楼","23456789123"); +#护士 +insert into nurse values +(101,1,"瓜文成","22","男"),(120,2,"周福","20","女"); +#医生 +insert into doctor values +(1001,1,"时雪安","22","男"),(1002,2,"夜只浩","20","男"); +#病房 +insert into ward values +(1,"一号病房"),(2,"二号病房"); +#病人 +insert into patient values +(10001,1,"时量涛","19","男"),(10002,2,"文贵文","20","女"); +#药品分类 +insert into type values +(1,"中药"),(2,"西药"); +#药房 +insert into pharmacy values +(1,"1号药房"),(2,"2号药房"); +#药品 +insert into pharmaceuticals values +(1,1,1,"安眠药",666,105.22),(2,2,2,"止泻药",888,110.11); +#分配 +insert into assignment values +(1,101,"2023-09-13"),(2,120,"2023-09-12"); +#诊断 +insert into diagnosis values +(10001,1001,"失眠症","2023-09-13 13:22:01"),(10002,1002,"结石","2023-09-12 16:13:11"); +#处方 +insert into prescription values +(1,10001,"注意休息","13:30:22"),(2,10002,"6666666","18:30:30"); ``` -- Gitee