diff --git "a/07 \345\210\230\346\226\207\351\224\213/20230913\345\214\273\347\224\237\350\215\257\345\223\201\347\227\205\344\272\272.md" "b/07 \345\210\230\346\226\207\351\224\213/20230913\345\214\273\347\224\237\350\215\257\345\223\201\347\227\205\344\272\272.md" new file mode 100644 index 0000000000000000000000000000000000000000..a8bf9f19dcfaf4e0ae79e0b7e2302c0013fe3389 --- /dev/null +++ "b/07 \345\210\230\346\226\207\351\224\213/20230913\345\214\273\347\224\237\350\215\257\345\223\201\347\227\205\344\272\272.md" @@ -0,0 +1,110 @@ +````java + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/13 23:37:23 */ +/*==============================================================*/ + +create database hospital charset utf8; +use hospital; + +drop table if exists department; + +drop table if exists doctor; + +drop table if exists drug; + +drop table if exists lookpatient; + +drop table if exists patient; + +drop table if exists patientEat; + +/*==============================================================*/ +/* Table: department */ +/*==============================================================*/ +create table department +( + doctor_id int not null, + department_id int not null auto_increment, + department_name varchar(10) not null, + department_tel int not null, + primary key (department_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doctor_id int not null auto_increment, + doctor_name varchar(10) not null, + doctor_age int not null, + doctor_sex char(1) not null, + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug +( + drug_id int not null auto_increment, + drug_name varchar(10) not null, + drug_price int not null, + drug_category varchar(10) not null, + primary key (drug_id) +); + +/*==============================================================*/ +/* Table: lookpatient */ +/*==============================================================*/ +create table lookpatient +( + doctor_id int not null, + patient_id int not null, + primary key (doctor_id, patient_id) +); + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient +( + patient_id int not null auto_increment, + patient_name varchar(10) not null, + patient_age int not null, + patient_sex char(1) not null, + patient_sfz int not null, + patient_tel int not null, + primary key (patient_id) +); + +/*==============================================================*/ +/* Table: patientEat */ +/*==============================================================*/ +create table patientEat +( + drug_id int not null, + patient_id int not null, + primary key (drug_id, patient_id) +); + +alter table department add constraint FK_employ foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table lookpatient add constraint FK_lookpatient foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table lookpatient add constraint FK_lookpatient2 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table patientEat add constraint FK_patientEat foreign key (drug_id) + references drug (drug_id) on delete restrict on update restrict; + +alter table patientEat add constraint FK_patientEat2 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; +``` + +```` +