diff --git "a/41 \345\221\250\344\272\232\350\276\211/.keep" "b/41 \345\221\250\344\272\232\350\276\211/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/41 \345\221\250\344\272\232\350\276\211/20230907\346\225\260\346\215\256\345\272\223\350\214\203\345\274\217.md" "b/41 \345\221\250\344\272\232\350\276\211/20230907\346\225\260\346\215\256\345\272\223\350\214\203\345\274\217.md" new file mode 100644 index 0000000000000000000000000000000000000000..95bb56f94146c6c1bde591c132fe47a418416063 --- /dev/null +++ "b/41 \345\221\250\344\272\232\350\276\211/20230907\346\225\260\346\215\256\345\272\223\350\214\203\345\274\217.md" @@ -0,0 +1,7 @@ +## 数据库范式 + +第一范式(1NF):原子性(存储的数据应该具有“不可再分性”) + +第二范式(2NF):唯一性 (消除非主键部分依赖联合主键中的部分字段)(一定要在第一范式已经满足的情况下) + +第三范式(3NF):独立性,消除传递依赖(非主键值不依赖于另一个非主键值) \ No newline at end of file diff --git "a/41 \345\221\250\344\272\232\350\276\211/20230910\345\233\276\344\271\246\351\246\206.md" "b/41 \345\221\250\344\272\232\350\276\211/20230910\345\233\276\344\271\246\351\246\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..ef9fb2e43d86eb831b43c7be8a6d4112ff68cb17 --- /dev/null +++ "b/41 \345\221\250\344\272\232\350\276\211/20230910\345\233\276\344\271\246\351\246\206.md" @@ -0,0 +1,271 @@ +## 笔记 + +1.先创建概念模型ER表 CDM + +2.将概念转成逻辑模型 LDM + +3.最后转成物理模型 PDM + +## 图书馆 + +```mysql +if exists(select 1 from sys.sysforeignkey where role='FK_BORROW2_BORROW_LIBRARY') then + alter table Borrow2 + delete foreign key FK_BORROW2_BORROW_LIBRARY +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_BORROW2_BORROW2_BORROW') then + alter table Borrow2 + delete foreign key FK_BORROW2_BORROW2_BORROW +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_MANAGE_MANAGE_LIBRARY') then + alter table manage + delete foreign key FK_MANAGE_MANAGE_LIBRARY +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_MANAGE_MANAGE2_WORKING') then + alter table manage + delete foreign key FK_MANAGE_MANAGE2_WORKING +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_SERVE_SERVE_WORKING') then + alter table serve + delete foreign key FK_SERVE_SERVE_WORKING +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_SERVE_SERVE2_BORROW') then + alter table serve + delete foreign key FK_SERVE_SERVE2_BORROW +end if; + +drop index if exists Borrow.Borrow_PK; + +drop table if exists Borrow; + +drop index if exists Borrow2.Borrow2_FK; + +drop index if exists Borrow2.Borrow_FK; + +drop index if exists Borrow2.Borrow2_PK; + +drop table if exists Borrow2; + +drop index if exists library.library_PK; + +drop table if exists library; + +drop index if exists manage.manage2_FK; + +drop index if exists manage.manage_FK; + +drop index if exists manage.manage_PK; + +drop table if exists manage; + +drop index if exists serve.serve_FK; + +drop index if exists serve.serve2_FK; + +drop index if exists serve.serve_PK; + +drop table if exists serve; + +drop index if exists "working personnel"."working personnel_PK"; + +drop table if exists "working personnel"; + +/*==============================================================*/ +/* Table: Borrow */ +/*==============================================================*/ +create table Borrow +( + Bor_id integer not null, + Bor_name varchar(10) not null, + Bor_level integer not null, + Bor_blacklist varchar(10) not null, + constraint PK_BORROW primary key (Bor_id) +); + +/*==============================================================*/ +/* Index: Borrow_PK */ +/*==============================================================*/ +create unique index Borrow_PK on Borrow ( +Bor_id ASC +); + +/*==============================================================*/ +/* Table: Borrow2 */ +/*==============================================================*/ +create table Borrow2 +( + lib_id integer not null, + Bor_id integer not null, + situation char(4) not null, + constraint PK_BORROW2 primary key (lib_id, Bor_id) +); + +/*==============================================================*/ +/* Index: Borrow2_PK */ +/*==============================================================*/ +create unique index Borrow2_PK on Borrow2 ( +lib_id ASC, +Bor_id ASC +); + +/*==============================================================*/ +/* Index: Borrow_FK */ +/*==============================================================*/ +create index Borrow_FK on Borrow2 ( +lib_id ASC +); + +/*==============================================================*/ +/* Index: Borrow2_FK */ +/*==============================================================*/ +create index Borrow2_FK on Borrow2 ( +Bor_id ASC +); + +/*==============================================================*/ +/* Table: library */ +/*==============================================================*/ +create table library +( + lib_id integer not null, + lib_name varchar(20) not null, + lib_state varchar(3) not null, + lib_author varchar(10) not null, + lib_publish varchar(20) not null, + lib_classes integer not null, + constraint PK_LIBRARY primary key (lib_id) +); + +/*==============================================================*/ +/* Index: library_PK */ +/*==============================================================*/ +create unique index library_PK on library ( +lib_id ASC +); + +/*==============================================================*/ +/* Table: manage */ +/*==============================================================*/ +create table manage +( + lib_id integer not null, + wor_id integer not null, + lib_state varchar(2) not null, + constraint PK_MANAGE primary key (lib_id, wor_id) +); + +/*==============================================================*/ +/* Index: manage_PK */ +/*==============================================================*/ +create unique index manage_PK on manage ( +lib_id ASC, +wor_id ASC +); + +/*==============================================================*/ +/* Index: manage_FK */ +/*==============================================================*/ +create index manage_FK on manage ( +lib_id ASC +); + +/*==============================================================*/ +/* Index: manage2_FK */ +/*==============================================================*/ +create index manage2_FK on manage ( +wor_id ASC +); + +/*==============================================================*/ +/* Table: serve */ +/*==============================================================*/ +create table serve +( + wor_id integer not null, + Bor_id integer not null, + constraint PK_SERVE primary key (wor_id, Bor_id) +); + +/*==============================================================*/ +/* Index: serve_PK */ +/*==============================================================*/ +create unique index serve_PK on serve ( +wor_id ASC, +Bor_id ASC +); + +/*==============================================================*/ +/* Index: serve2_FK */ +/*==============================================================*/ +create index serve2_FK on serve ( +Bor_id ASC +); + +/*==============================================================*/ +/* Index: serve_FK */ +/*==============================================================*/ +create index serve_FK on serve ( +wor_id ASC +); + +/*==============================================================*/ +/* Table: "working personnel" */ +/*==============================================================*/ +create table "working personnel" +( + wor_id integer not null, + wor_name varchar(4) not null, + wor_position varchar(10) not null, + wor_range varchar(20) not null, + wor_state varchar(4) not null, + constraint "PK_WORKING PERSONNEL" primary key (wor_id) +); + +/*==============================================================*/ +/* Index: "working personnel_PK" */ +/*==============================================================*/ +create unique index "working personnel_PK" on "working personnel" ( +wor_id ASC +); + +alter table Borrow2 + add constraint FK_BORROW2_BORROW_LIBRARY foreign key (lib_id) + references library (lib_id) + on update restrict + on delete restrict; + +alter table Borrow2 + add constraint FK_BORROW2_BORROW2_BORROW foreign key (Bor_id) + references Borrow (Bor_id) + on update restrict + on delete restrict; + +alter table manage + add constraint FK_MANAGE_MANAGE_LIBRARY foreign key (lib_id) + references library (lib_id) + on update restrict + on delete restrict; + +alter table manage + add constraint FK_MANAGE_MANAGE2_WORKING foreign key (wor_id) + references "working personnel" (wor_id) + on update restrict + on delete restrict; + +alter table serve + add constraint FK_SERVE_SERVE_WORKING foreign key (wor_id) + references "working personnel" (wor_id) + on update restrict + on delete restrict; + +alter table serve + add constraint FK_SERVE_SERVE2_BORROW foreign key (Bor_id) + references Borrow (Bor_id) + on update restrict + on delete restrict; +``` \ No newline at end of file diff --git "a/41 \345\221\250\344\272\232\350\276\211/\345\274\200\345\255\246\347\254\254\344\270\200\350\257\276\345\277\203\345\276\227.md" "b/41 \345\221\250\344\272\232\350\276\211/\345\274\200\345\255\246\347\254\254\344\270\200\350\257\276\345\277\203\345\276\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..8ac961567469370b5afa262b557c335938018e35 --- /dev/null +++ "b/41 \345\221\250\344\272\232\350\276\211/\345\274\200\345\255\246\347\254\254\344\270\200\350\257\276\345\277\203\345\276\227.md" @@ -0,0 +1,7 @@ +新学期新气象。 + +好好学习,天天向上。 + +做好学习规划,网络资源利用,不局限于课堂。 + +学习新思想,争做新青年。 \ No newline at end of file diff --git "a/41 \345\221\250\344\272\232\350\276\211/\346\225\260\346\215\256\345\272\223\350\256\276\350\256\241.md" "b/41 \345\221\250\344\272\232\350\276\211/\346\225\260\346\215\256\345\272\223\350\256\276\350\256\241.md" new file mode 100644 index 0000000000000000000000000000000000000000..5d5ec70e3c81fb96e9253b82a44e6bf99e0ac793 --- /dev/null +++ "b/41 \345\221\250\344\272\232\350\276\211/\346\225\260\346\215\256\345\272\223\350\256\276\350\256\241.md" @@ -0,0 +1,134 @@ +## 笔记 + +### 表与表之间的关系(和关联方法): + +1.一对一 1-1 + +2.一对多 1-n + +一对一和一对多的关联:都是将一所在表的主键放在另一张表里当外键。 + +3.多对多 n-m + +多对多的关联:引入第三张表,前两张表的主键放入表中做外键。 + +### E-R图设计 + +方块 实体 + +菱形 关系 + +椭圆 属性 + +## 练习 + +```mysql +院系,专业,学生,教师,课程,教室等图表设计 +create database school charset utf8; + +use school; + +-- 院系表 +create table department( + d_id int primary key, + d_name varchar(10), + d_address varchar(10) +); +insert into department values +(110,'软件工程学院','望云楼'), +(120,'信息工程学院','辛耕楼'), +(119,'建筑工程学院','万源楼'); + +-- 专业表 +create table speciality( + s_id int primary key, + s_name varchar(10), + d_id int, + foreign key (d_id) references department(d_id) +); +insert into speciality values +(11,'软件技术与开发',110), +(22,'信息技术',120), +(33,'建筑设计',119); + +-- 教室表 +create table classroom( +r_id int PRIMARY KEY, +r_name varchar(10) +); +insert into classroom values +(1,'实训一'), +(2,'实训二'), +(3,'实训三'); + +-- 班级表 +create table class( + c_id int primary key, + c_name varchar(10), + s_id int, + foreign key (s_id) references speciality(s_id) +); +insert into class values +(1,'软件技术1班',11), +(2,'软件技术2班',11), +(3,'软件技术3班',11); + +-- 课程表 +CREATE TABLE course( + couseId int PRIMARY key, + courseName varchar(10), + c_id int, + r_id int, + foreign key (c_id) references class(c_id), + foreign key (r_id) references classroom(r_id) +); +insert into course VALUES +(1,'java',1,2), +(2,'html',2,3), +(3,'mysql',3,1); + +-- 教师表 +create table teacher( + t_id int primary key, + t_name varchar(10), + couseId int, + foreign key (couseId) references course(couseId) +); +insert into teacher values +(1,'张三',1), +(2,'张四',2), +(3,'张五',3); + +-- 选修表 +create table `select` ( + selectId int primary key, + couseId int, + time varchar(20), + t_id int, + r_id int, + foreign key (couseId) references course(couseId), + foreign key (t_id) references teacher(t_id), + foreign key (r_id) references classroom(r_id) +); +insert into `select` values +(1,1,'周一上午',2,3), +(2,2,'周二下午',1,2), +(3,3,'周三上午',3,1); + +-- 学生表 +create table student ( + id int primary key, + name varchar(10), + sex varchar(5), + age int, + address varchar(20), + c_id int, + selectId int, + foreign key (c_id) references class(c_id), + foreign key (selectId) references `select`(selectId) +); +insert into student values +(11111,'小明','男',18,'团结里1',1,1), +(22222,'小花','女',118,'团结里2',2,2), +(33333,'小王','男',1118,'团结里3',3,3); +``` \ No newline at end of file