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); +``` +