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] =?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