From c90a0fb5bd63e96817dcc06ae2a756b2538288d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E6=AD=A3=E6=B3=A2?= <1938448998@qq.com> Date: Wed, 13 Sep 2023 19:52:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=9D=E6=9C=88=E5=8D=81=E4=B8=89=E5=8F=B7?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\351\253\230\347\272\247.md" | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 "09 \346\233\271\346\255\243\346\263\242/20230913 \346\225\260\346\215\256\345\272\223\351\253\230\347\272\247.md" diff --git "a/09 \346\233\271\346\255\243\346\263\242/20230913 \346\225\260\346\215\256\345\272\223\351\253\230\347\272\247.md" "b/09 \346\233\271\346\255\243\346\263\242/20230913 \346\225\260\346\215\256\345\272\223\351\253\230\347\272\247.md" new file mode 100644 index 0000000..13f1e40 --- /dev/null +++ "b/09 \346\233\271\346\255\243\346\263\242/20230913 \346\225\260\346\215\256\345\272\223\351\253\230\347\272\247.md" @@ -0,0 +1,114 @@ +# 作业 + + + +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023-09-13 17:26:56 */ +/*==============================================================*/ + +create database hospital charset utf8; +use hospital; + +drop table if exists cure; + +drop table if exists doctor; + +drop table if exists drug; + +drop table if exists grab; + +drop table if exists patient; + +/*==============================================================*/ +/* Table: cure */ +/*==============================================================*/ + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor #医生 +( + d_id int(2) not null auto_increment, # 医生编号 + d_name varchar(5) not null, # 医生姓名 + d_type varchar(10) not null, # 医生类型 + d_sex varchar(2) not null, # 医生性别 + d_age varchar(2) not null, # 医生年龄 + primary key (d_id) +); +insert into doctor (d_id,d_name,d_type,d_sex,d_age) values +('1','陈佳炜','胃科','男','18'), +('2','林俊伟','妇产科','女','18'), +('3','代瑞','脑科','男','18'); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug #药品 +( + dr_id int(2) not null auto_increment, # 药品编号 + dr_name varchar(5) not null, # 药品名称 + primary key (dr_id) +); +insert into drug (dr_id,dr_name) values +('1','止泻药'), +('2','阿司匹林'), +('3','胃炎药'); + +/*==============================================================*/ +/* Table: grab */ +/*==============================================================*/ + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient #病人 +( + p_id int(2) not null auto_increment, #病人病号 + p_name varchar(5) not null, #病人姓名 + p_symptom varchar(10) not null, #病人症状 + p_sex varchar(2) not null, #病人性别 + p_age varchar(2) not null, #病人年龄 + primary key (p_id) +); +insert into patient (p_id,p_name,p_symptom,p_sex,p_age) values +('1','张三','头疼','男','18'), +('2','李四','肚子疼','男','18'), +('3','王五','胃炎','男','18'); +create table cure #开药单 +( + p_id int not null, #病人病号 + d_id int not null, #医生编号 + primary key (p_id, d_id) +); + +insert into cure (p_id,d_id)values +('1','2'), +('2','1'), +('3','1'); +create table grab #抓 +( + p_id int not null, #病人病号 + dr_id int not null, #药品编号 + primary key (p_id, dr_id) +); +insert into grab (p_id,dr_id) values +('1','2'), +('2','1'), +('3','3'); +alter table cure add constraint FK_cure foreign key (p_id) + references patient (p_id) on delete restrict on update restrict; + +alter table cure add constraint FK_cure2 foreign key (d_id) + references doctor (d_id) on delete restrict on update restrict; + +alter table grab add constraint FK_grab foreign key (p_id) + references patient (p_id) on delete restrict on update restrict; + +alter table grab add constraint FK_grab2 foreign key (dr_id) + references drug (dr_id) on delete restrict on update restrict; + + +``` + -- Gitee