From 3048292a6448eb5b0809a2a0695eaf0c57538a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E7=BF=94?= <2045602860@qq.com> Date: Thu, 14 Sep 2023 04:07:23 +0000 Subject: [PATCH] =?UTF-8?q?34=20=E5=88=98=E6=99=BA=E7=BF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘智翔 <2045602860@qq.com> --- ...73\347\224\237\347\263\273\347\273\237.md" | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 "34 \345\210\230\346\231\272\347\277\224/\345\214\273\347\224\237\347\263\273\347\273\237.md" diff --git "a/34 \345\210\230\346\231\272\347\277\224/\345\214\273\347\224\237\347\263\273\347\273\237.md" "b/34 \345\210\230\346\231\272\347\277\224/\345\214\273\347\224\237\347\263\273\347\273\237.md" new file mode 100644 index 0000000..46dc890 --- /dev/null +++ "b/34 \345\210\230\346\231\272\347\277\224/\345\214\273\347\224\237\347\263\273\347\273\237.md" @@ -0,0 +1,98 @@ +```mysql +笔记 +如果一个主体的属性有多个值,那这个属性就可以拆成一个新主体 + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023-09-14 08:55:14 */ +/*==============================================================*/ + + +drop table if exists doctor; + +drop table if exists drug; + +drop table if exists medical; + +drop table if exists patients; + +drop table if exists prescription; + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doc_id int not null auto_increment, + doc_no varchar(20) not null, + doc_name varchar(10) not null, + doc_sex varchar(5), + primary key (doc_id) +); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug +( + dro_id int not null auto_increment, + dro_name varchar(20) not null, + primary key (dro_id) +); + +/*==============================================================*/ +/* Table: medical */ +/*==============================================================*/ +create table medical +( + ca_id int not null auto_increment, + doc_id int, + bat_no int, + date date, + diagnose varchar(50), + primary key (ca_id) +); + +/*==============================================================*/ +/* Table: patients */ +/*==============================================================*/ +create table patients +( + bat_no int not null auto_increment, + bat_name varchar(10) not null, + bat_age int, + bat_sex varchar(5), + primary key (bat_no) +); + +/*==============================================================*/ +/* Table: prescription */ +/*==============================================================*/ +create table prescription +( + dro_id int not null, + ca_id int not null, + bat_no int, + usa varchar(20), + dosage varchar(20), + primary key (dro_id, ca_id) +); + +alter table medical add constraint FK_Relationship_1 foreign key (doc_id) + references doctor (doc_id) on delete restrict on update restrict; + +alter table medical add constraint FK_Relationship_2 foreign key (bat_no) + references patients (bat_no) on delete restrict on update restrict; + +alter table prescription add constraint FK_Relationship_5 foreign key (bat_no) + references patients (bat_no) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription foreign key (dro_id) + references drug (dro_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription2 foreign key (ca_id) + references medical (ca_id) on delete restrict on update restrict; + + + +``` \ No newline at end of file -- Gitee