diff --git "a/18 \345\276\220\346\260\270\346\267\263/20230913\344\275\234\344\270\232.md" "b/18 \345\276\220\346\260\270\346\267\263/20230913\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..9e7cdd3ea807a208f8c7f9f98b75961feddd06fa --- /dev/null +++ "b/18 \345\276\220\346\260\270\346\267\263/20230913\344\275\234\344\270\232.md" @@ -0,0 +1,118 @@ +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/13 21:29:20 */ +/*==============================================================*/ +create database hospital charset utf8; + +use hospital; + +drop table if exists DEPARTMENT; + +drop table if exists DISPENSARY; + +drop table if exists DOCTOR; + +drop table if exists PATIENT; + +drop table if exists PRESCRIPT; + +/*==============================================================*/ +/* Table: DEPARTMENT */ +/*==============================================================*/ +create table DEPARTMENT #科室 +( + DEPARTMENT_ID int not null auto_increment, + DEPARTMENT_NUMBER varchar(20) not null, + primary key (DEPARTMENT_ID) +); + +insert into department values (null,110); + +insert into department values (null,119); + +insert into department values (null,120); + +insert into department values (null,911); + +insert into department values (null,100086); + +insert into department values (null,12345); + +/*==============================================================*/ +/* Table: DISPENSARY */ +/*==============================================================*/ +create table DISPENSARY #取药 +( + DISPENSARY_ID int not null auto_increment, + DISPENSARY_NAME varchar(10) not null, + DISPENSARY_USAGE varchar(100) not null, + primary key (DISPENSARY_ID) +); + +insert into dispensary values (null,'吗丁啉','饭后吃'); + +/*==============================================================*/ +/* 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_GENDER char(1) not null, + primary key (DOCTOR_ID) +); + +insert into doctor values (1,1,'东方饭店',12,'男'); + +insert into doctor values (null,2,'西方饭店',21,'女'); + + +/*==============================================================*/ +/* Table: PATIENT */ +/*==============================================================*/ +create table PATIENT #病人 +( + PATIENT_ID int not null auto_increment, + DOCTOR_ID int, + PATIENT_NAME varchar(10) not null, + PATIENT_GENDER char(1) not null, + PATIENT_NUMBER varchar(20) not null, + primary key (PATIENT_ID) +); + +insert into patient values (null,1,'本地接送','男','12138'); + +insert into patient values (null,2,'外地接送','女','12333'); + +/*==============================================================*/ +/* Table: PRESCRIPT */ +/*==============================================================*/ +create table PRESCRIPT #药方 +( + DISPENSARY_ID int not null, + PATIENT_ID int not null, + primary key (DISPENSARY_ID, PATIENT_ID) +); + +insert into prescript values (1,1); + +insert into prescript values (2,2); + +alter table DOCTOR add constraint FK_SUBORDINATE foreign key (DEPARTMENT_ID) + references DEPARTMENT (DEPARTMENT_ID) on delete restrict on update restrict; + +alter table PATIENT add constraint FK_DIAGNOSE foreign key (DOCTOR_ID) + references DOCTOR (DOCTOR_ID) on delete restrict on update restrict; + +alter table PRESCRIPT add constraint FK_PRESCRIPT foreign key (DISPENSARY_ID) + references DISPENSARY (DISPENSARY_ID) on delete restrict on update restrict; + +alter table PRESCRIPT add constraint FK_PRESCRIPT2 foreign key (PATIENT_ID) + references PATIENT (PATIENT_ID) on delete restrict on update restrict; + + +``` + diff --git "a/18 \345\276\220\346\260\270\346\267\263/20230913\347\254\224\350\256\260.md" "b/18 \345\276\220\346\260\270\346\267\263/20230913\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..4978f3e454c0fdde43b644d29eaa0d4930fffab7 --- /dev/null +++ "b/18 \345\276\220\346\260\270\346\267\263/20230913\347\254\224\350\256\260.md" @@ -0,0 +1 @@ +若表内字段有多个值时,可将这个值单独取出新建一个表 \ No newline at end of file