diff --git "a/19\345\275\255\345\213\207\346\226\214/\347\254\224\350\256\260/\345\214\273\351\231\242.md" "b/19\345\275\255\345\213\207\346\226\214/\347\254\224\350\256\260/\345\214\273\351\231\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..92a0ee5bb88a4215b7e593723fb01dc05b29c681 --- /dev/null +++ "b/19\345\275\255\345\213\207\346\226\214/\347\254\224\350\256\260/\345\214\273\351\231\242.md" @@ -0,0 +1,198 @@ +E_R图 + +![image-20230914112503321](https://s2.loli.net/2023/09/14/hazeIFEfy73VDsn.png) + + + +# 代码 + +```MYSQL +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/14 11:17:52 */ +/*==============================================================*/ +CREATE DATABASE hospital1 charset utf8; +use hospital1; + +drop table if exists aaa; + +drop table if exists administrative; + +drop table if exists doctor; + +drop table if exists doctor_patients; + +drop table if exists drug; + +drop table if exists hospital; + +drop table if exists patients; + +drop table if exists patients_reception; + +drop table if exists prescription; + +drop table if exists prescription_drug; + +drop table if exists reception; + +/*==============================================================*/ +/* Table: aaa */ +/*==============================================================*/ +create table aaa +( + durg_id int not null, + reception_id int not null, + primary key (durg_id, reception_id) +); + +/*==============================================================*/ +/* Table: administrative */ +/*==============================================================*/ +create table administrative +( + administrative_id int not null auto_increment, + hospital_id char(10), + administrative����name varchar(40) not null, + primary key (administrative_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doctor_id int not null auto_increment, + administrative_id int, + doctor_name varchar(20) not null, + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: doctor_patients */ +/*==============================================================*/ +create table doctor_patients +( + patients_id int not null, + doctor_id int not null, + primary key (patients_id, doctor_id) +); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug +( + durg_id int not null auto_increment, + drug_name varchar(50) not null, + drug_mioney varchar(100) not null, + primary key (durg_id) +); + +/*==============================================================*/ +/* Table: hospital */ +/*==============================================================*/ +create table hospital +( + hospital_id char(10) not null, + hospital_name varchar(40) not null, + primary key (hospital_id) +); + +/*==============================================================*/ +/* Table: patients */ +/*==============================================================*/ +create table patients +( + patients_id int not null auto_increment, + prescribe_id char(10), + patients_name varchar(20) not null, + primary key (patients_id) +); + +/*==============================================================*/ +/* Table: patients_reception */ +/*==============================================================*/ +create table patients_reception +( + patients_id int not null, + reception_id int not null, + primary key (patients_id, reception_id) +); + +/*==============================================================*/ +/* Table: prescription */ +/*==============================================================*/ +create table prescription +( + prescribe_time char(10) not null, + prescribe_id char(10) not null, + doctor_id int, + reception_id int, + patients_id int, + prescribe_amount char(10) not null, + primary key (prescribe_id) +); + +/*==============================================================*/ +/* Table: prescription_drug */ +/*==============================================================*/ +create table prescription_drug +( + durg_id int not null, + prescribe_id char(10) not null, + primary key (durg_id, prescribe_id) +); + +/*==============================================================*/ +/* Table: reception */ +/*==============================================================*/ +create table reception +( + reception_id int not null auto_increment, + reception_name varchar(10) not null, + primary key (reception_id) +); + +alter table aaa add constraint FK_aaa foreign key (durg_id) + references drug (durg_id) on delete restrict on update restrict; + +alter table aaa add constraint FK_aaa2 foreign key (reception_id) + references reception (reception_id) on delete restrict on update restrict; + +alter table administrative add constraint FK_Relationship_6 foreign key (hospital_id) + references hospital (hospital_id) on delete restrict on update restrict; + +alter table doctor add constraint FK_Relationship_7 foreign key (administrative_id) + references administrative (administrative_id) on delete restrict on update restrict; + +alter table doctor_patients add constraint FK_doctor_patients foreign key (patients_id) + references patients (patients_id) on delete restrict on update restrict; + +alter table doctor_patients add constraint FK_doctor_patients2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table patients add constraint FK_prescription_patients2 foreign key (prescribe_id) + references prescription (prescribe_id) on delete restrict on update restrict; + +alter table patients_reception add constraint FK_patients_reception foreign key (patients_id) + references patients (patients_id) on delete restrict on update restrict; + +alter table patients_reception add constraint FK_patients_reception2 foreign key (reception_id) + references reception (reception_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_doctor_prescribe foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription_patients foreign key (patients_id) + references patients (patients_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_price_statistics foreign key (reception_id) + references reception (reception_id) on delete restrict on update restrict; + +alter table prescription_drug add constraint FK_prescription_drug foreign key (durg_id) + references drug (durg_id) on delete restrict on update restrict; + +alter table prescription_drug add constraint FK_prescription_drug2 foreign key (prescribe_id) + references prescription (prescribe_id) on delete restrict on update restrict; +