diff --git "a/56 \350\265\265\346\225\217/20230914\345\214\273\351\231\242.md" "b/56 \350\265\265\346\225\217/20230914\345\214\273\351\231\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..d2409b94c1ab2dcad64f444729b57ea875ab4539 --- /dev/null +++ "b/56 \350\265\265\346\225\217/20230914\345\214\273\351\231\242.md" @@ -0,0 +1,143 @@ +作业 + +``` +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/14 9:47:40 */ +/*==============================================================*/ + +CREATE DATABASE z CHARSET utf8; +use z; +drop table if exists diagnose2; + +drop table if exists doctor; + +drop table if exists drug; + +drop table if exists patient; + +drop table if exists pharmacy; + +drop table if exists prescription; + +drop table if exists registration; + +drop table if exists type; + +/*==============================================================*/ +/* Table: diagnose2 */ +/*==============================================================*/ +create table diagnose2 +( + patient_id int not null, + doctor_id int not null, + illness varchar(255) not null, + primary key (patient_id, doctor_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doctor_id int not null auto_increment, + type_id int, + doctor_name varchar(10) not null, + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug +( + drug_id int not null auto_increment, + drug_name varchar(20) not null, + drug_intro varchar(200) not null, + primary key (drug_id) +); + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient +( + patient_id int not null auto_increment, + patient_name varchar(5) not null, + patient_sex char(1) not null, + primary key (patient_id) +); + +/*==============================================================*/ +/* Table: pharmacy */ +/*==============================================================*/ +create table pharmacy +( + pharmacy int not null auto_increment, + pharmacy_name varchar(10) not null, + primary key (pharmacy) +); + +/*==============================================================*/ +/* Table: prescription */ +/*==============================================================*/ +create table prescription +( + prescription_id int not null, + doctor_id int, + patient_id int, + drug_id int, + pharmacy int, + primary key (prescription_id) +); + +/*==============================================================*/ +/* Table: registration */ +/*==============================================================*/ +create table registration +( + reg_id char(10) not null, + doctor_id int not null, + patient_id int not null, + primary key (reg_id, doctor_id, patient_id) +); + +/*==============================================================*/ +/* Table: type */ +/*==============================================================*/ +create table type +( + type_id int not null auto_increment, + type_name varchar(5) not null, + primary key (type_id) +); + +alter table diagnose2 add constraint FK_diagnose foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table diagnose2 add constraint FK_diagnose2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table doctor add constraint FK_Relationship_5 foreign key (type_id) + references type (type_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_Relationship_6 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_Relationship_7 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_Relationship_8 foreign key (drug_id) + references drug (drug_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_Relationship_9 foreign key (pharmacy) + references pharmacy (pharmacy) on delete restrict on update restrict; + +alter table registration add constraint FK_registration foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table registration add constraint FK_registration2 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +``` +