diff --git "a/13 \350\224\241\345\230\211\344\271\220/0914\347\254\224\350\256\260\345\212\240\344\275\234\344\270\232.md" "b/13 \350\224\241\345\230\211\344\271\220/0914\347\254\224\350\256\260\345\212\240\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..7f42f5c9e71de2043ea981734f9c9a86fce4dfd4 --- /dev/null +++ "b/13 \350\224\241\345\230\211\344\271\220/0914\347\254\224\350\256\260\345\212\240\344\275\234\344\270\232.md" @@ -0,0 +1,171 @@ +如果一个主体的属性有多个值,那这个属性就可以拆成一个新主体 + +```mysql +create database hospital charset utf8; + +use hospital; + +/*==============================================================*/ +/* 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); +``` + diff --git "a/13 \350\224\241\345\230\211\344\271\220/b9f15c44a08aadf90bd62e92666ccdd.png" "b/13 \350\224\241\345\230\211\344\271\220/b9f15c44a08aadf90bd62e92666ccdd.png" new file mode 100644 index 0000000000000000000000000000000000000000..a6e4f558b0374bb6f0ca66bf1d2df34b2b52b72e Binary files /dev/null and "b/13 \350\224\241\345\230\211\344\271\220/b9f15c44a08aadf90bd62e92666ccdd.png" differ diff --git "a/13 \350\224\241\345\230\211\344\271\220/hosp.sql" "b/13 \350\224\241\345\230\211\344\271\220/hosp.sql" new file mode 100644 index 0000000000000000000000000000000000000000..6a0305cede5c45663c3f7d426783fd4fa7f27145 --- /dev/null +++ "b/13 \350\224\241\345\230\211\344\271\220/hosp.sql" @@ -0,0 +1,76 @@ +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/14 11:18:54 */ +/*==============================================================*/ + +create database hospital charset utf8; + +use hospital; +drop table if exists Doctor; + +drop table if exists "administrative office"; + +drop table if exists "inpatient ward"; + +drop table if exists sick; + +/*==============================================================*/ +/* Table: Doctor */ +/*==============================================================*/ +create table Doctor +( + Doctor_id int not null auto_increment, + "administrative office_id" int not null, + Doctor_name varchar(10) not null, + Doctor_age int not null, + primary key (Doctor_id) +); + +/*==============================================================*/ +/* Table: "administrative office" */ +/*==============================================================*/ +create table "administrative office" +( + "administrative office_id" int not null auto_increment, + "administrative office_name" varchar(10) not null, + "administrative office_address" varchar(20) not null, + "administrative office_number" int not null, + primary key ("administrative office_id") +); + +/*==============================================================*/ +/* Table: "inpatient ward" */ +/*==============================================================*/ +create table "inpatient ward" +( + "inpatient ward_id" int not null auto_increment, + "administrative office_id" int not null, + "inpatient ward_name" varchar(10) not null, + primary key ("inpatient ward_id") +); + +/*==============================================================*/ +/* Table: sick */ +/*==============================================================*/ +create table sick +( + sick_id int not null auto_increment, + "inpatient ward_id" int not null, + Doctor_id int not null, + sick_name varchar(10) not null, + sick_sex varchar(5) not null, + primary key (sick_id) +); + +alter table Doctor add constraint FK_subordination foreign key ("administrative office_id") + references "administrative office" ("administrative office_id") on delete restrict on update restrict; + +alter table "inpatient ward" add constraint FK_Composition foreign key ("administrative office_id") + references "administrative office" ("administrative office_id") on delete restrict on update restrict; + +alter table sick add constraint FK_Check foreign key ("inpatient ward_id") + references "inpatient ward" ("inpatient ward_id") on delete restrict on update restrict; + +alter table sick add constraint FK_cure foreign key (Doctor_id) + references Doctor (Doctor_id) on delete restrict on update restrict; +