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 0000000000000000000000000000000000000000..23aa04653842cc8d19fc4838ccdb9080ead51b9f --- /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,256 @@ +# 笔记 + +#### 如果一个主体的属性有多个值,那这个属性就可以拆成一个新主体 + +# 作业 + +### 医院数据库设计 + + 需求分析 + +科室(科室编号,科室名,地址,联系电话) + +病人(病历号,姓名,年龄,性别) + +病房(病房编号,病房名) + +药品(药品编号,药品名称,价格,重量) + +药品分类(分类编号,分类名) + +药房 (药房编号,药房名) + +护士(工号,姓名,年龄,性别) + +![image-20230914011846375](https://s2.loli.net/2023/09/14/JgjkF7sh3MxXiqW.png) + +![image-20230914012312885](https://s2.loli.net/2023/09/14/X89l3YLiEfydJcx.png) + +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/14 1:24:04 */ +/*==============================================================*/ +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; + +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, + assignment_date date 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: 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 */ +/*==============================================================*/ +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, + departmen_id int 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, + 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, + prescription_say varchar(255) not null, + prescription_time time 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 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 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; + +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; + +#科室 +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"); +``` +