From 5e67fb6305c6610066d472a3c2fb4f3885157130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E8=89=AF=E6=B6=9B?= <12071381+shiliangtao@user.noreply.gitee.com> Date: Tue, 12 Sep 2023 14:32:09 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石良涛 <12071381+shiliangtao@user.noreply.gitee.com> --- ...56\345\272\223\350\214\203\345\274\217.md" | 10 + ...61\346\236\266\346\236\204\345\233\276.md" | 191 ++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20230907 \346\225\260\346\215\256\345\272\223\350\214\203\345\274\217.md" create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20230912 \347\224\265\345\275\261\346\236\266\346\236\204\345\233\276.md" diff --git "a/20 \347\237\263\350\211\257\346\266\233/20230907 \346\225\260\346\215\256\345\272\223\350\214\203\345\274\217.md" "b/20 \347\237\263\350\211\257\346\266\233/20230907 \346\225\260\346\215\256\345\272\223\350\214\203\345\274\217.md" new file mode 100644 index 0000000..fb5ddb2 --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20230907 \346\225\260\346\215\256\345\272\223\350\214\203\345\274\217.md" @@ -0,0 +1,10 @@ +### 数据库范式 + + 范式也是一种规则 + +1. 要求字段内容,不可再分割,为了保证数字原子性 +2. 在满足范式1 的要求基础上,要求非主键字段要完全依赖主键(非主键要依赖整个联合主键)而不能只依赖部分 +3. 满足范式2 的基础上,非关键属性要直接依赖于主键不能出现传递依赖。 + +但是实际开发当中不会完全按照范式来设计,因为需求不同,所以有时会故意反范式 + diff --git "a/20 \347\237\263\350\211\257\346\266\233/20230912 \347\224\265\345\275\261\346\236\266\346\236\204\345\233\276.md" "b/20 \347\237\263\350\211\257\346\266\233/20230912 \347\224\265\345\275\261\346\236\266\346\236\204\345\233\276.md" new file mode 100644 index 0000000..b6d7973 --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20230912 \347\224\265\345\275\261\346\236\266\346\236\204\345\233\276.md" @@ -0,0 +1,191 @@ +### 电影架构图 + +![图片1](https://s2.loli.net/2023/09/12/lA7GCrDE1m54pbo.png) + +~~~mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/12 18:32:00 */ +/*==============================================================*/ +CREATE DATABASE movie_db CHARSET utf8; +use movie_db; + +drop table if exists director; + +drop table if exists film; + +drop table if exists language; + +drop table if exists movieInfo; + +drop table if exists participants; + +drop table if exists protagonist; + +drop table if exists region; + +drop table if exists score; + +drop table if exists scriptwriter; + +drop table if exists user; + +/*==============================================================*/ +/* Table: director */ +/*==============================================================*/ +create table director +( + part_id char(10) not null, + movie_id char(8) not null, + primary key (part_id, movie_id) +); + +/*==============================================================*/ +/* Table: film */ +/*==============================================================*/ +create table film +( + film_id char(10) not null, + user_id char(10) not null, + film_name char(10) not null, + film_title char(10) not null, + text char(10) not null, + appraise char(10), + primary key (film_id) +); + +/*==============================================================*/ +/* Table: language */ +/*==============================================================*/ +create table language +( + lang_id char(10) not null, + lang_name varchar(5), + primary key (lang_id) +); + +/*==============================================================*/ +/* Table: movieInfo */ +/*==============================================================*/ +create table movieInfo +( + movie_id char(8) not null, + film_id char(10) not null, + sc_id char(10) not null, + lang_id char(10) not null, + movie_name varchar(20) not null, + movie_time int not null, + type_id char(5) not null, + release_date datetime not null, + alias varchar(20) not null, + primary key (movie_id) +); + +/*==============================================================*/ +/* Table: participants */ +/*==============================================================*/ +create table participants +( + part_id char(10) not null, + name char(10) not null, + age int, + primary key (part_id) +); + +/*==============================================================*/ +/* Table: protagonist */ +/*==============================================================*/ +create table protagonist +( + part_id char(10) not null, + movie_id char(8) not null, + sex char(1) not null, + birthday varchar(15) not null, + `else` varchar(10), + profession char(30) not null, + address varchar(15), + primary key (part_id, movie_id) +); + +/*==============================================================*/ +/* Table: region */ +/*==============================================================*/ +create table region +( + reg_id char(10) not null, + movie_id char(8), + reg_name char(25) not null, + primary key (reg_id) +); + +/*==============================================================*/ +/* Table: score */ +/*==============================================================*/ +create table score +( + sc_id char(10) not null, + user_id char(10) not null, + grade char(10) not null, + primary key (sc_id) +); + +/*==============================================================*/ +/* Table: scriptwriter */ +/*==============================================================*/ +create table scriptwriter +( + part_id char(10) not null, + movie_id char(8) not null, + primary key (part_id, movie_id) +); + +/*==============================================================*/ +/* Table: user */ +/*==============================================================*/ +create table user +( + user_id char(10) not null, + user_name varchar(20) not null, + user_sex char(1) not null, + primary key (user_id) +); + +alter table director add constraint FK_director foreign key (part_id) + references participants (part_id) on delete restrict on update restrict; + +alter table director add constraint FK_director2 foreign key (movie_id) + references movieInfo (movie_id) on delete restrict on update restrict; + +alter table film add constraint FK_write foreign key (user_id) + references user (user_id) on delete restrict on update restrict; + +alter table movieInfo add constraint FK_evaluate foreign key (film_id) + references film (film_id) on delete restrict on update restrict; + +alter table movieInfo add constraint FK_mark foreign key (sc_id) + references score (sc_id) on delete restrict on update restrict; + +alter table movieInfo add constraint FK_select foreign key (lang_id) + references language (lang_id) on delete restrict on update restrict; + +alter table protagonist add constraint FK_protagonist foreign key (part_id) + references participants (part_id) on delete restrict on update restrict; + +alter table protagonist add constraint FK_protagonist2 foreign key (movie_id) + references movieInfo (movie_id) on delete restrict on update restrict; + +alter table region add constraint FK_publish foreign key (movie_id) + references movieInfo (movie_id) on delete restrict on update restrict; + +alter table score add constraint FK_comment foreign key (user_id) + references user (user_id) on delete restrict on update restrict; + +alter table scriptwriter add constraint FK_scriptwriter foreign key (part_id) + references participants (part_id) on delete restrict on update restrict; + +alter table scriptwriter add constraint FK_scriptwriter2 foreign key (movie_id) + references movieInfo (movie_id) on delete restrict on update restrict; + + +~~~ + -- Gitee From 9f3226a8d44c0ca54f6daf413adb9906b45a639f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E8=89=AF=E6=B6=9B?= <12071381+shiliangtao@user.noreply.gitee.com> Date: Thu, 14 Sep 2023 05:02:16 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 石良涛 <12071381+shiliangtao@user.noreply.gitee.com> --- ...42\346\225\260\346\215\256\345\272\223.md" | 256 ++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" diff --git "a/20 \347\237\263\350\211\257\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" "b/20 \347\237\263\350\211\257\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000..6ff1e2e --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20230913 \345\214\273\351\231\242\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,256 @@ +# 笔记 + +#### 如果一个主体的属性有多个值,那这个属性就可以拆成一个新主体 + +# 作业 + +### 医院数据库设计 + + 需求分析 + +科室(科室编号,科室名,地址,联系电话) + +病人(病历号,姓名,年龄,性别) + +病房(病房编号,病房名) + +药品(药品编号,药品名称,价格,重量) + +药品分类(分类编号,分类名) + +药房 (药房编号,药房名) + +护士(工号,姓名,年龄,性别) + +![image-20230914011846375](https://s2.loli.net/2023/09/14/JgjkF7sh3MxXiqW.png) + +![image-20230914012312885](https://s2.loli.net/2023/09/14/X89l3YLiEfydJcx.png) + +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/14 1:24:04 */ +/*==============================================================*/ +create database yy charset utf8; +use yy; + +drop table if exists assignment; + +drop table if exists department; + +drop table if exists diagnosis; + +drop table if exists doctor; + +drop table if exists nurse; + +drop table if exists patient; + +drop table if exists pharmaceuticals; + +drop table if exists pharmacy; + +drop table if exists prescription; + +drop table if exists type; + +drop table if exists ward; + +/*==============================================================*/ +/* Table: assignment */ +/*==============================================================*/ +create table assignment +( + ward_id int not null, + nurse_id char(10) not null, + assignment_date date not null, + primary key (ward_id, nurse_id) +); + +/*==============================================================*/ +/* Table: department */ +/*==============================================================*/ +create table department +( + departmen_id int not null auto_increment, + department_name varchar(10) not null, + department_add varchar(50) not null, + department_tel char(11) not null, + primary key (departmen_id) +); + +/*==============================================================*/ +/* Table: diagnosis */ +/*==============================================================*/ +create table diagnosis +( + patient_id char(10) not null, + doctor_id char(10) not null, + diagnosis_name varchar(255) not null, + diagnosis_time datetime not null, + primary key (patient_id, doctor_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor +( + doctor_id char(10) not null, + departmen_id int not null, + doctor_name varchar(4) not null, + doctor_age char(2) not null, + doctor_sex char(1) not null, + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: nurse */ +/*==============================================================*/ +create table nurse +( + nurse_id char(10) not null, + departmen_id int not null, + nurse_name varchar(4) not null, + nurse_age char(2) not null, + nurse_sex char(1) not null, + primary key (nurse_id) +); + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient +( + patient_id char(10) not null, + ward_id int not null, + patient_name varchar(4) not null, + patient_age char(2) not null, + patient_sex char(1) not null, + primary key (patient_id) +); + +/*==============================================================*/ +/* Table: pharmaceuticals */ +/*==============================================================*/ +create table pharmaceuticals +( + pharmaceuticals_id int not null auto_increment, + pharmacy_id int not null, + type_id int not null, + pharmaceuticals_name varchar(10) not null, + pharmaceuticals_prrice int not null, + pharmaceuticals_wigat decimal(5,2) not null, + primary key (pharmaceuticals_id) +); + +/*==============================================================*/ +/* Table: pharmacy */ +/*==============================================================*/ +create table pharmacy +( + pharmacy_id int not null auto_increment, + pharmacy_name varchar(10) not null, + primary key (pharmacy_id) +); + +/*==============================================================*/ +/* Table: prescription */ +/*==============================================================*/ +create table prescription +( + pharmaceuticals_id int not null, + patient_id char(10) not null, + prescription_say varchar(255) not null, + prescription_time time not null, + primary key (pharmaceuticals_id, patient_id) +); + +/*==============================================================*/ +/* Table: type */ +/*==============================================================*/ +create table type +( + type_id int not null auto_increment, + type_name varchar(3) not null, + primary key (type_id) +); + +/*==============================================================*/ +/* Table: ward */ +/*==============================================================*/ +create table ward +( + ward_id int not null auto_increment, + ward_name varchar(10) not null, + primary key (ward_id) +); + +alter table assignment add constraint FK_assignment foreign key (ward_id) + references ward (ward_id) on delete restrict on update restrict; + +alter table assignment add constraint FK_assignment2 foreign key (nurse_id) + references nurse (nurse_id) on delete restrict on update restrict; + +alter table diagnosis add constraint FK_diagnosis foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table diagnosis add constraint FK_diagnosis2 foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table doctor add constraint FK_belong foreign key (departmen_id) + references department (departmen_id) on delete restrict on update restrict; + +alter table nurse add constraint FK_belongs foreign key (departmen_id) + references department (departmen_id) on delete restrict on update restrict; + +alter table patient add constraint FK_live foreign key (ward_id) + references ward (ward_id) on delete restrict on update restrict; + +alter table pharmaceuticals add constraint FK_deposit foreign key (pharmacy_id) + references pharmacy (pharmacy_id) on delete restrict on update restrict; + +alter table pharmaceuticals add constraint FK_have foreign key (type_id) + references type (type_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription foreign key (pharmaceuticals_id) + references pharmaceuticals (pharmaceuticals_id) on delete restrict on update restrict; + +alter table prescription add constraint FK_prescription2 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +#科室 +insert into department values +(1,"内科","2楼","12345678912"),(2,"外科","5楼","23456789123"); +#护士 +insert into nurse values +(101,1,"瓜文成","22","男"),(120,2,"周福","20","女"); +#医生 +insert into doctor values +(1001,1,"时雪安","22","男"),(1002,2,"夜只浩","20","男"); +#病房 +insert into ward values +(1,"一号病房"),(2,"二号病房"); +#病人 +insert into patient values +(10001,1,"时量涛","19","男"),(10002,2,"文贵文","20","女"); +#药品分类 +insert into type values +(1,"中药"),(2,"西药"); +#药房 +insert into pharmacy values +(1,"1号药房"),(2,"2号药房"); +#药品 +insert into pharmaceuticals values +(1,1,1,"安眠药",666,105.22),(2,2,2,"止泻药",888,110.11); +#分配 +insert into assignment values +(1,101,"2023-09-13"),(2,120,"2023-09-12"); +#诊断 +insert into diagnosis values +(10001,1001,"失眠症","2023-09-13 13:22:01"),(10002,1002,"结石","2023-09-12 16:13:11"); +#处方 +insert into prescription values +(1,10001,"注意休息","13:30:22"),(2,10002,"6666666","18:30:30"); +``` + -- Gitee