diff --git "a/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/CDM.png" "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/CDM.png" new file mode 100644 index 0000000000000000000000000000000000000000..0c840eb05b340e6ab6643e4e9ab50201b932ec34 Binary files /dev/null and "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/CDM.png" differ diff --git "a/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/LDM.png" "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/LDM.png" new file mode 100644 index 0000000000000000000000000000000000000000..bba80ceb9da04feb41103cd24c6792f5d196baa2 Binary files /dev/null and "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/LDM.png" differ diff --git "a/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/PDM.png" "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/PDM.png" new file mode 100644 index 0000000000000000000000000000000000000000..71091790bc27e64d61000f996eaf2d812a4a2752 Binary files /dev/null and "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/PDM.png" differ diff --git "a/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\345\212\237\350\203\275\345\261\225\347\244\272.md" "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\345\212\237\350\203\275\345\261\225\347\244\272.md" new file mode 100644 index 0000000000000000000000000000000000000000..37a77e8614f836b7f5a0e6ba3b1f3302345d4956 --- /dev/null +++ "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\345\212\237\350\203\275\345\261\225\347\244\272.md" @@ -0,0 +1,33 @@ +# 数据库高级应用第一课笔记 + +## 表与表的关系: + +### 1.一对多: + +​ 一个记录在表A中可以对应多个记录在表B中,但表B中的每个记录只能对应表A中的一个记录 + +### 2.一对一: + +​ 一个记录在表A中只对应一个记录在表B中,反之亦然。 + +### 3.多对多: + +​ 表A中的一个记录可以对应表B中的多个记录,而表B中的一个记录也可以对应表A中的多个记录,通常需要通过一个关联表来实现 + +## 设计数据库的约束(范式): + +1. **第一范式(1NF)**: + - 数据表中的每一列都必须是原子的,即列中的每个值都是不可再分的基本数据项。 + - 例如,一个表中的某一列不能包含多个值或集合。 +2. **第二范式(2NF)**: + - 在满足第一范式的基础上,要求每个非主属性完全函数依赖于主键,即每个非主属性都必须依赖于整个主键(而不是主键的一部分)。 + - 例如,如果主键是复合主键,那么所有非主属性必须依赖于主键的所有部分。 +3. **第三范式(3NF)**: + - 在满足第二范式的基础上,要求每个非主属性直接依赖于主键,而不是依赖于其他非主属性。 + - 也就是说,消除传递依赖。例如,若A -> B和B -> C,那么应有A -> C,以消除B的依赖关系。 + + + + + + \ No newline at end of file diff --git "a/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\351\253\230\347\272\247\345\272\224\347\224\250\347\254\254\344\270\200\350\257\276\347\254\224\350\256\260.md" "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\351\253\230\347\272\247\345\272\224\347\224\250\347\254\254\344\270\200\350\257\276\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..37a77e8614f836b7f5a0e6ba3b1f3302345d4956 --- /dev/null +++ "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\351\253\230\347\272\247\345\272\224\347\224\250\347\254\254\344\270\200\350\257\276\347\254\224\350\256\260.md" @@ -0,0 +1,33 @@ +# 数据库高级应用第一课笔记 + +## 表与表的关系: + +### 1.一对多: + +​ 一个记录在表A中可以对应多个记录在表B中,但表B中的每个记录只能对应表A中的一个记录 + +### 2.一对一: + +​ 一个记录在表A中只对应一个记录在表B中,反之亦然。 + +### 3.多对多: + +​ 表A中的一个记录可以对应表B中的多个记录,而表B中的一个记录也可以对应表A中的多个记录,通常需要通过一个关联表来实现 + +## 设计数据库的约束(范式): + +1. **第一范式(1NF)**: + - 数据表中的每一列都必须是原子的,即列中的每个值都是不可再分的基本数据项。 + - 例如,一个表中的某一列不能包含多个值或集合。 +2. **第二范式(2NF)**: + - 在满足第一范式的基础上,要求每个非主属性完全函数依赖于主键,即每个非主属性都必须依赖于整个主键(而不是主键的一部分)。 + - 例如,如果主键是复合主键,那么所有非主属性必须依赖于主键的所有部分。 +3. **第三范式(3NF)**: + - 在满足第二范式的基础上,要求每个非主属性直接依赖于主键,而不是依赖于其他非主属性。 + - 也就是说,消除传递依赖。例如,若A -> B和B -> C,那么应有A -> C,以消除B的依赖关系。 + + + + + + \ No newline at end of file diff --git "a/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\266\205\345\270\202\347\263\273\347\273\237.sql" "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\266\205\345\270\202\347\263\273\347\273\237.sql" new file mode 100644 index 0000000000000000000000000000000000000000..017d73b9940fbba29bbd63179948a598b6e6414b --- /dev/null +++ "b/\345\217\266\345\212\237\347\205\247/20240903 \346\225\260\346\215\256\345\272\223\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\350\266\205\345\270\202\347\263\273\347\273\237.sql" @@ -0,0 +1,104 @@ +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2024/9/4 8:22:28 */ +/*==============================================================*/ + + +drop table if exists customer; + +drop table if exists goods; + +drop table if exists link01; + +drop table if exists link02; + +drop table if exists link03; + +drop table if exists shop; + +/*==============================================================*/ +/* Table: customer */ +/*==============================================================*/ +create table customer +( + c_Id int not null auto_increment, + c_Name varchar(255), + c_Phone int, + c_Sex varchar(10), + c_age int, + address varchar(255), + primary key (c_Id) +); + +/*==============================================================*/ +/* Table: goods */ +/*==============================================================*/ +create table goods +( + g_Id int not null auto_increment, + g_Name varchar(255), + g_Inprice float(1), + g_Price float(1), + count int, + status int, + primary key (g_Id) +); + +/*==============================================================*/ +/* Table: link01 */ +/*==============================================================*/ +create table link01 +( + g_Id int not null, + c_Id int not null, + primary key (g_Id, c_Id) +); + +/*==============================================================*/ +/* Table: link02 */ +/*==============================================================*/ +create table link02 +( + s_Id int not null, + c_Id int not null, + primary key (s_Id, c_Id) +); + +/*==============================================================*/ +/* Table: link03 */ +/*==============================================================*/ +create table link03 +( + s_Id int not null auto_increment, + g_Id int not null, + primary key (s_Id, g_Id) +); + +/*==============================================================*/ +/* Table: shop */ +/*==============================================================*/ +create table shop +( + s_Id int not null auto_increment, + s_Name varchar(255), + primary key (s_Id) +); + +alter table link01 add constraint FK_link01 foreign key (g_Id) + references goods (g_Id) on delete restrict on update restrict; + +alter table link01 add constraint FK_link04 foreign key (c_Id) + references customer (c_Id) on delete restrict on update restrict; + +alter table link02 add constraint FK_link02 foreign key (s_Id) + references shop (s_Id) on delete restrict on update restrict; + +alter table link02 add constraint FK_link05 foreign key (c_Id) + references customer (c_Id) on delete restrict on update restrict; + +alter table link03 add constraint FK_link03 foreign key (s_Id) + references shop (s_Id) on delete restrict on update restrict; + +alter table link03 add constraint FK_link06 foreign key (g_Id) + references goods (g_Id) on delete restrict on update restrict; +