diff --git "a/\345\215\242\346\257\224\344\274\246/crebas.sql" "b/\345\215\242\346\257\224\344\274\246/crebas.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b61554ee3810a47d64fe616c502721ea21a6d4a4 --- /dev/null +++ "b/\345\215\242\346\257\224\344\274\246/crebas.sql" @@ -0,0 +1,64 @@ +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2024/9/6 20:17:43 */ +/*==============================================================*/ + + +drop table if exists clazz; + +drop table if exists much; + +drop table if exists student; + +drop table if exists teacherbiao; + +/*==============================================================*/ +/* Table: clazz */ +/*==============================================================*/ +create table clazz +( + cid int not null, + cren numeric(50,0) not null, + primary key (cid) +); + +/*==============================================================*/ +/* Table: much */ +/*==============================================================*/ +create table much +( + tid numeric(50,0) not null, + sid numeric(50,0) not null, + primary key (tid, sid) +); + +/*==============================================================*/ +/* Table: student */ +/*==============================================================*/ +create table student +( + sid numeric(50,0) not null, + cid int not null, + sname varchar(255) not null, + primary key (sid) +); + +/*==============================================================*/ +/* Table: teacherbiao */ +/*==============================================================*/ +create table teacherbiao +( + tid numeric(50,0) not null, + tname varchar(255) not null, + primary key (tid) +); + +alter table much add constraint FK_much foreign key (tid) + references teacherbiao (tid) on delete restrict on update restrict; + +alter table much add constraint FK_much2 foreign key (sid) + references student (sid) on delete restrict on update restrict; + +alter table student add constraint FK_one foreign key (cid) + references clazz (cid) on delete restrict on update restrict; + diff --git "a/\345\215\242\346\257\224\344\274\246/lbl.md" "b/\345\215\242\346\257\224\344\274\246/lbl.md" new file mode 100644 index 0000000000000000000000000000000000000000..d3f03efcce84cfb39961649b06baf2f235abf257 --- /dev/null +++ "b/\345\215\242\346\257\224\344\274\246/lbl.md" @@ -0,0 +1,26 @@ +#表之间表关系# +一对一 (1:1) +在这种关系中,一个表中的每一条记录只与另一个表中的一条记录相关联。 +实现方式通常是通过在一个表中创建一个外键,指向另一个表的主键。 +例如,员工表和员工详细信息表之间的关系。 +一对多 (1:N) +在这种关系中,一个表(父表)中的每一条记录可以与另一个表(子表)中的多条记录相关联,但子表中的每条记录只能与父表中的一条记录相关联。 +通常实现方式是在子表中创建一个外键,该外键指向父表的主键。 +例如,部门表和员工表之间的关系,一个部门可以有多个员工,但每个员工只能属于一个部门。 +多对多 (N:M) +当两个表中的每条记录都可以与对方表中的多条记录相关联时,就需要使用多对多的关系。 +实现方式通常是创建一个关联表或交叉引用表,该表至少包含来自两个表的外键。 +例如,学生表和课程表之间的关系,一个学生可以选修多门课程,一门课程也可以被多名学生选修。 +二、数据库设计三大范式 +第一范式 (1NF) - 无重复组 +每个表中的每个列都必须是不可分割的基本数据项,即原子性。 +表中的每一行都是唯一的,不允许有重复的数据行。 +这意味着消除所有重复的组,并将它们放入单独的表中。 +第二范式 (2NF) - 完全依赖 +表必须已经在第一范式下。 +所有的非主键列都完全依赖于整个主键(而非部分依赖)。 +为了满足这一要求,通常需要确保表具有一个单一的候选键,并且所有的非键属性完全依赖于这个键。 +第三范式 (3NF) - 非传递依赖 +表必须已经在第二范式下。 +所有的非主键列都直接依赖于主键,并且不存在非主键列间的依赖关系(即没有传递依赖)。 +这意味着如果存在非主键列A依赖于非主键列B,而B依赖于主键,则应该将A和B分离到不同的表中。 \ No newline at end of file diff --git "a/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 231942.png" "b/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 231942.png" new file mode 100644 index 0000000000000000000000000000000000000000..a605d392c185c721321c72938e8f98406417296c Binary files /dev/null and "b/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 231942.png" differ diff --git "a/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 232459.png" "b/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 232459.png" new file mode 100644 index 0000000000000000000000000000000000000000..6e07587d706642074bfd1455d474bc6bc8ec2a91 Binary files /dev/null and "b/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 232459.png" differ diff --git "a/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 233602.png" "b/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 233602.png" new file mode 100644 index 0000000000000000000000000000000000000000..79c7aa65013326cced26282e8d6ee229f6516b86 Binary files /dev/null and "b/\345\215\242\346\257\224\344\274\246/\345\261\217\345\271\225\346\210\252\345\233\276 2024-09-04 233602.png" differ