diff --git "a/54 \345\217\266\345\255\220\350\261\252/9.13\344\275\234\344\270\232.md" "b/54 \345\217\266\345\255\220\350\261\252/9.13\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..d733fafe29f75361b63e426e5a055aea1bed992d --- /dev/null +++ "b/54 \345\217\266\345\255\220\350\261\252/9.13\344\275\234\344\270\232.md" @@ -0,0 +1,106 @@ +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/13 21:45:21 */ +/*==============================================================*/ + + +drop table if exists department; + +drop table if exists doctor; + +drop table if exists drug; + +drop table if exists guahao; + +drop table if exists patient; + +drop table if exists warehouse; + +/*==============================================================*/ +/* Table: department */ +/*==============================================================*/ +create table department +( + department_id int not null auto_increment, + department_name varchar(20) not null, + department_address varchar(50) not null, + primary key (department_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doctor_id int not null auto_increment, + department_id int, + doctor_name varchar(10) not null, + doctor_age int not null, + doctor_sex varchar(10) not null, + illness varchar(20) not null, + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug +( + drug_id int not null auto_increment, + drug_name varchar(20) not null, + treatment varchar(50) not null, + primary key (drug_id) +); + +/*==============================================================*/ +/* Table: guahao */ +/*==============================================================*/ +create table guahao +( + patient_id int not null, + doctor_id int not null, + primary key (patient_id, doctor_id) +); + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient +( + patient_id int not null auto_increment, + patient_name varchar(20) not null, + patient_age int not null, + patient_sex varchar(20) not null, + symptom varchar(100) not null, + primary key (patient_id) +); + +/*==============================================================*/ +/* Table: warehouse */ +/*==============================================================*/ +create table warehouse +( + drug_id int not null, + doctor_id int not null, + primary key (drug_id, doctor_id) +); + +alter table doctor add constraint FK_Relationship_3 foreign key (department_id) + references department (department_id) on delete restrict on update restrict; + +alter table guahao add constraint FK_guahao foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table guahao add constraint FK_guahao2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table warehouse add constraint FK_warehouse foreign key (drug_id) + references drug (drug_id) on delete restrict on update restrict; + +alter table warehouse add constraint FK_warehouse2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + + +``` + diff --git "a/54 \345\217\266\345\255\220\350\261\252/\347\254\254\345\205\255\345\244\251\347\254\224\350\256\260.md" "b/54 \345\217\266\345\255\220\350\261\252/\347\254\254\345\205\255\345\244\251\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..c474662cccc732c7a1cfd5fc81373c4b9985813a --- /dev/null +++ "b/54 \345\217\266\345\255\220\350\261\252/\347\254\254\345\205\255\345\244\251\347\254\224\350\256\260.md" @@ -0,0 +1 @@ +如果一个主体的属性有多个值那这个属性就可以拆成一个新的主体 \ No newline at end of file