diff --git "a/29 \350\267\257\347\216\262/20230904 \345\274\200\345\255\246\347\254\254\344\270\200\350\257\276.md" "b/29 \350\267\257\347\216\262/20230905 \345\274\200\345\255\246\347\254\254\344\270\200\350\257\276.md" similarity index 100% rename from "29 \350\267\257\347\216\262/20230904 \345\274\200\345\255\246\347\254\254\344\270\200\350\257\276.md" rename to "29 \350\267\257\347\216\262/20230905 \345\274\200\345\255\246\347\254\254\344\270\200\350\257\276.md" diff --git "a/29 \350\267\257\347\216\262/20230905 \345\244\264\350\204\221\351\243\216\346\232\264.md" "b/29 \350\267\257\347\216\262/20230906 \345\244\264\350\204\221\351\243\216\346\232\264.md" similarity index 100% rename from "29 \350\267\257\347\216\262/20230905 \345\244\264\350\204\221\351\243\216\346\232\264.md" rename to "29 \350\267\257\347\216\262/20230906 \345\244\264\350\204\221\351\243\216\346\232\264.md" diff --git "a/29 \350\267\257\347\216\262/20230906 \345\244\264\350\204\221\351\243\216\346\232\264\346\234\200\347\273\210\347\211\210.md" "b/29 \350\267\257\347\216\262/20230907 \345\244\264\350\204\221\351\243\216\346\232\264\346\234\200\347\273\210\347\211\210.md" similarity index 100% rename from "29 \350\267\257\347\216\262/20230906 \345\244\264\350\204\221\351\243\216\346\232\264\346\234\200\347\273\210\347\211\210.md" rename to "29 \350\267\257\347\216\262/20230907 \345\244\264\350\204\221\351\243\216\346\232\264\346\234\200\347\273\210\347\211\210.md" diff --git "a/29 \350\267\257\347\216\262/20230907 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/29 \350\267\257\347\216\262/20230908 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" similarity index 100% rename from "29 \350\267\257\347\216\262/20230907 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" rename to "29 \350\267\257\347\216\262/20230908 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" diff --git "a/29 \350\267\257\347\216\262/20230913 \345\214\273\351\231\242.md" "b/29 \350\267\257\347\216\262/20230913 \345\214\273\351\231\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..f63f36f6049810cad77a83a79242e544bb03cf25 --- /dev/null +++ "b/29 \350\267\257\347\216\262/20230913 \345\214\273\351\231\242.md" @@ -0,0 +1,256 @@ +## 笔记 + +如果一个主体的属性有多个值,那么这个属性就可以拆成一个新的主体。 + +当三个表都是多对多关系时,可以另外设置一个表,将这三个表全部以1对多的关系连接这个另外设置的表, + +或者,在cdm时,先把其中两个表设成多对多的关系,等到ldm时,再将第三张表与生成的表连接。 + +LDM照片:https://s2.loli.net/2023/09/14/jdrQUcfnAsleLw6.jpg + +## 作业 + +```mysql +-- 创建数据库 +create database hospital charset utf8; + +-- 使用数据库 +use hospital; + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023-09-13 19:43:32 */ +/*==============================================================*/ + + +drop table if exists administrative_office;-- 科室 + +drop table if exists doctor;-- 医生 + +drop table if exists drug;-- 药品 + +drop table if exists inpatient_ward;-- 病房 + +drop table if exists nurse;-- 护士 + +drop table if exists nurse2;-- 护理 + +drop table if exists patient;-- 病人 + +drop table if exists user;-- 用 + +drop table if exists ward_type;-- 病房类型 + +/*==============================================================*/ +/* Table: administrative_office */ +/*==============================================================*/ +create table administrative_office -- 科室 +( + administrative_office_id int not null auto_increment,-- 科室编号 + administrative_office_name char(10) not null,-- 科室名称 + administrative_office_phone numeric(11,0) not null,-- 科室电话 + administrative_office_address char(100) not null,-- 科室地址 + primary key (administrative_office_id) +); + +/*==============================================================*/ +/* Table: doctor */ +/*==============================================================*/ +create table doctor-- 医生 +( + doctor_id int not null auto_increment,-- 医生编号 + administrative_office_id int,-- 科室编号 + doctor_name char(10) not null,-- 医生姓名 + doctor_sex char(1) not null,-- 医生性别 + doctor_post char(10) not null,-- 医生职务 + doctor_age char(10) not null,-- 医生年龄 + doctor_price numeric(6,0) not null,-- 医生工资 + doctor_phone int not null,-- 医生电话 + primary key (doctor_id) +); + +/*==============================================================*/ +/* Table: drug */ +/*==============================================================*/ +create table drug-- 药品 +( + drug_id int not null auto_increment,-- 药品编号 + drug_name char(10) not null,-- 药品名称 + drug_manufacturers char(10) not null,-- 药品厂家 + drug_price float(8,2) not null,-- 药品价格 + drug_date date not null,-- 生产日期 + primary key (drug_id) +); + +/*==============================================================*/ +/* Table: inpatient_ward */ +/*==============================================================*/ +create table inpatient_ward-- 病房 +( + inpatient_ward_id int not null auto_increment,-- 病房编号 + ward_type_id int not null,-- 病房类型编号 + inpatient_ward_name int not null,-- 病房名称 + inpatient_ward_floor char(10) not null,-- 病房楼层 + inpatient_ward_sum char(10) not null,-- 病房栋数 + primary key (inpatient_ward_id) +); + +/*==============================================================*/ +/* Table: nurse */ +/*==============================================================*/ +create table nurse-- 护士 +( + nurse_id int not null auto_increment,-- 护士编号 + nurse_name char(10) not null,-- 护士姓名 + nurse_sex char(1) not null,-- 护士性别 + nurse_age char(5) not null,-- 护士年龄 + nurse_price numeric(6,0) not null,-- 护士工资 + primary key (nurse_id) +); + +/*==============================================================*/ +/* Table: nurse2 */ +/*==============================================================*/ +create table nurse2-- 护理 +( + nurse_id int not null,-- 护士编号 + patient_id int not null,-- 患者编号 + primary key (nurse_id, patient_id) +); + +/*==============================================================*/ +/* Table: patient */ +/*==============================================================*/ +create table patient-- 病人 +( + patient_id int not null auto_increment,-- 患者编号 + doctor_id int,-- 医生编号 + inpatient_ward_id int,-- 病房编号 + patient_name char(10) not null,-- 患者名称 + patient_sex char(1) not null,-- 患者性别 + patient_age int not null,-- 患者年龄 + patient_history char(100) not null,-- 患者年龄 + primary key (patient_id) +); + +/*==============================================================*/ +/* Table: "use" */ +/*==============================================================*/ +create table user-- 用 +( + drug_id int not null,-- 药品编号 + patient_id int not null,-- 患者编号 + primary key (drug_id, patient_id) +); + +/*==============================================================*/ +/* Table: ward_type */ +/*==============================================================*/ +create table ward_type-- 病房类型 +( + ward_type_id int not null auto_increment,-- 病房类型编号 + administrative_office_id int,-- 科室编号 + ward_type_name char(10) not null,-- 病房类型名称 + ward_type_price numeric(6,0) not null,-- 病房类型价格 + primary key (ward_type_id) +); + +alter table doctor add constraint FK_subordinate foreign key (administrative_office_id) + references administrative_office (administrative_office_id) on delete restrict on update restrict; + +alter table inpatient_ward add constraint FK_set foreign key (ward_type_id) + references ward_type (ward_type_id) on delete restrict on update restrict; + +alter table nurse2 add constraint FK_nurse foreign key (nurse_id) + references nurse (nurse_id) on delete restrict on update restrict; + +alter table nurse2 add constraint FK_nurse2 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table patient add constraint FK_Indications foreign key (doctor_id) + references doctor (doctor_id) on delete restrict on update restrict; + +alter table patient add constraint FK_check_in foreign key (inpatient_ward_id) + references inpatient_ward (inpatient_ward_id) on delete restrict on update restrict; + +alter table user add constraint FK_use foreign key (drug_id) + references drug (drug_id) on delete restrict on update restrict; + +alter table user add constraint FK_use2 foreign key (patient_id) + references patient (patient_id) on delete restrict on update restrict; + +alter table ward_type add constraint FK_belong foreign key (administrative_office_id) + references administrative_office (administrative_office_id) on delete restrict on update restrict; + + + +-- 添加数据 + +-- 插入科室表 +INSERT INTO administrative_office VALUES +(1,'骨科','16022585641','5栋101'), +(2,'普外科','16045928945','5栋102'), +(3,'妇科','15856842584','5栋103'), +(4,'内科','16053985698','5栋104'); + +-- 插入护士表 +INSERT INTO nurse VALUES +(331,'吴天灵','女','25','5600'), +(332,'刘桂花','女','28','5800'), +(333,'王娜娜','女','22','4500'), +(334,'吴胡丽','女','32','8200'); + + +-- 插入病房类型表 +INSERT INTO ward_type VALUES +(441,1,'ICU','15000'), +(442,2,'普通病房','120'), +(443,3,'vip独立病房','560'); + +-- 插入病房表 +INSERT INTO inpatient_ward VALUES +(551,441,101,'1层','6栋'), +(552,442,102,'2层','6栋'), +(553,443,103,'3层','7栋'), +(554,442,104,'4层','8栋'); + +-- 插入药品表 +INSERT INTO drug VALUES +(221,'布洛芬缓释胶囊','北京同仁堂','11','2023-04-12'), +(222,'复方氨基比林','北京双鹤药业','42','2023-02-12'), +(223,'苯巴比妥钠','北京双鹤药业','15','2022-12-15'), +(224,'复方愈创木酚磺酸钾','厦门星鲨制药','15','2023-06-26'), +(225,'维生素B2片','吉林敖东药业集团','13','2023-2-08'); + + + +-- 插入医生表 +INSERT INTO doctor VALUES +(111,'1','李斯','男','住院医师','45岁','6500','1505526528'), +(112,'2','张武','男','主治医师','32岁','5200','1605566656'), +(113,'3','王䦹福','女','副主任医师','52岁','7500','1605558551'), +(114,'2','刘民生','男','主任医师','56岁','5600','1803694413'); + +-- 插入病人表 +INSERT INTO patient VALUES +(881,111,551,'李黎明','男','25','花粉过敏'), +(882,112,554,'张栋国','男','42','花生过敏'), +(883,114,552,'刘建国','男','56','无'), +(884,113,553,'张立业','男','45','无'); + + +-- 插入护理表 +INSERT INTO nurse2 VALUES +(331,881), +(332,882), +(333,883); + +-- 插入用药表 +INSERT INTO user VALUES +(221,881), +(222,882), +(223,883); + + +``` +