diff --git "a/03 \350\265\226\345\277\203\345\246\215/20230913 \345\214\273\351\231\242.jpg" "b/03 \350\265\226\345\277\203\345\246\215/20230913 \345\214\273\351\231\242.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..0106173c243bf52f78550abc819a5d7d81aa036b Binary files /dev/null and "b/03 \350\265\226\345\277\203\345\246\215/20230913 \345\214\273\351\231\242.jpg" differ diff --git "a/03 \350\265\226\345\277\203\345\246\215/20230913 \345\214\273\351\231\242.md" "b/03 \350\265\226\345\277\203\345\246\215/20230913 \345\214\273\351\231\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..d5fddc308faf3c25a05d1f4f6a1f44e8b4287734 --- /dev/null +++ "b/03 \350\265\226\345\277\203\345\246\215/20230913 \345\214\273\351\231\242.md" @@ -0,0 +1,176 @@ +如果一个主体的属性有多个值,那这个属性就可以拆成一个新主体 + +## 医院 + +![医院](C:\Users\Administrator\Desktop\医院.jpg) + +```mysql +create database hospital_1 charset utf8; + +use hospital_1; + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/13 21:45:56 */ +/*==============================================================*/ + + +drop table if exists department; + +drop table if exists doctor; + +drop table if exists doctor_patient_diagnosis; + +drop table if exists doctor_patient_registered; + +drop table if exists medicine; + +drop table if exists patient; + +drop table if exists pharmacy; + +drop table if exists ward; + +/*==============================================================*/ +/* Table: department */ +/*==============================================================*/ +create table department +( + department_id int not null auto_increment, + department_name varchar(7) not null, + department_tel char(11) not null, + department_address varchar(10) not null, + primary key (department_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doctor_id int not null auto_increment, + department_id int not null, + doctor_name varchar(4) not null, + doctor_sex char(1) not null, + doctor_title varchar(5) not null, + doctor_age int not null, + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: doctor_patient_diagnosis */ +/*==============================================================*/ +create table doctor_patient_diagnosis +( + diagnosis_id int not null auto_increment, + patient_id int not null, + doctor_id int not null, + medicine_jd int not null, + diagnosis_price numeric(7,2) not null, + primary key (diagnosis_id) +); + +/*==============================================================*/ +/* Table: doctor_patient_registered */ +/*==============================================================*/ +create table doctor_patient_registered +( + registered_id int not null auto_increment, + patient_id int not null, + doctor_id int not null, + registered_date datetime not null, + registered_price numeric(2,0) not null, + primary key (registered_id) +); + +/*==============================================================*/ +/* Table: medicine */ +/*==============================================================*/ +create table medicine +( + medicine_jd int not null auto_increment, + pharmacy_id int not null, + medicine_name varchar(10) not null, + medicine_price numeric(5,2) not null, + medicine_function varchar(50) not null, + medicine_ingredients varchar(50) not null, + medicine_num int not null, + primary key (medicine_jd) +); + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient +( + patient_id int not null auto_increment, + patient_name varchar(4) not null, + patient_age int not null, + patient_sex char(1) not null, + primary key (patient_id) +); + +/*==============================================================*/ +/* Table: pharmacy */ +/*==============================================================*/ +create table pharmacy +( + pharmacy_id int not null auto_increment, + pharmacy_name varchar(7) not null, + primary key (pharmacy_id) +); + +/*==============================================================*/ +/* Table: ward */ +/*==============================================================*/ +create table ward +( + ward_id int not null auto_increment, + department_id int not null, + bed_id char(3) not null, + primary key (ward_id) +); + +alter table doctor add constraint FK_department_doctor_belong foreign key (department_id) + references department (department_id) on delete restrict on update restrict; + +alter table doctor_patient_diagnosis add constraint FK_doctor_patient_diagnosis foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table doctor_patient_diagnosis add constraint FK_doctor_patient_diagnosis2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table doctor_patient_diagnosis add constraint FK_mediciner_patient_diagnosis foreign key (medicine_jd) + references medicine (medicine_jd) on delete restrict on update restrict; + +alter table doctor_patient_registered add constraint FK_doctor_patient_registered foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table doctor_patient_registered add constraint FK_doctor_patient_registered2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table medicine add constraint FK_medicine_pharmacy_storage foreign key (pharmacy_id) + references pharmacy (pharmacy_id) on delete restrict on update restrict; + +alter table ward add constraint FK_department_ward_belong foreign key (department_id) + references department (department_id) on delete restrict on update restrict; + + +INSERT INTO `department` VALUES (5, '皮肤科', '08756934127', '门诊楼5层'); + +INSERT INTO `doctor` VALUES (3, 5, 'Kim', '女', '主治医师', 45); + +INSERT INTO `pharmacy` VALUES (7, '7房'); + +INSERT INTO `medicine` VALUES (8, 7, '氯雷他定', 60.00, '接触性皮炎', '氯', 1); + +INSERT INTO `ward` VALUES (1, 5, '#01'); + +INSERT INTO `patient` VALUES (1, 'isa', 21, '女'); + +INSERT INTO `doctor_patient_registered` VALUES (1, 1, 3, '2020-11-12 10:52:16', 50); + +INSERT INTO `doctor_patient_diagnosis` VALUES (1, 1, 3, 8, 110.00); + +``` +