diff --git "a/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/3a1f83e0c727de4f722b8b1e4800ce6.png" "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/3a1f83e0c727de4f722b8b1e4800ce6.png" new file mode 100644 index 0000000000000000000000000000000000000000..faec884f269207aa266e8c9fced22f55b7d5a8c5 Binary files /dev/null and "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/3a1f83e0c727de4f722b8b1e4800ce6.png" differ diff --git "a/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/66ddf01aa4e90953ee85f9bf1d129c5.png" "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/66ddf01aa4e90953ee85f9bf1d129c5.png" new file mode 100644 index 0000000000000000000000000000000000000000..4429520fd1dbb48f7b7fba92325681b1a72f2037 Binary files /dev/null and "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/66ddf01aa4e90953ee85f9bf1d129c5.png" differ diff --git "a/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/8be77df9823d03eed054043b91dc566.png" "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/8be77df9823d03eed054043b91dc566.png" new file mode 100644 index 0000000000000000000000000000000000000000..f384dda3ab39d66bf269ddb32b9d2b925142f37b Binary files /dev/null and "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/8be77df9823d03eed054043b91dc566.png" differ diff --git "a/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.MD" "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.MD" new file mode 100644 index 0000000000000000000000000000000000000000..a12db42f1037f845b77ebd74abf060f172b43684 --- /dev/null +++ "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/\346\226\260\345\273\272 \346\226\207\346\234\254\346\226\207\346\241\243.MD" @@ -0,0 +1,105 @@ +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2024/9/4 22:43:02 */ +/*==============================================================*/ + + +drop table if exists chaoshi; + +drop table if exists kh; + +drop table if exists mm; + +drop table if exists shangpin; + +drop table if exists yuangon; + +drop table if exists zl; + +/*==============================================================*/ +/* Table: chaoshi */ +/*==============================================================*/ +create table chaoshi +( + sid int not null, + sname varchar(255), + primary key (sid) +); + +/*==============================================================*/ +/* Table: kh */ +/*==============================================================*/ +create table kh +( + kid int not null, + yid int not null, + kname varchar(255), + primary key (kid) +); + +/*==============================================================*/ +/* Table: mm */ +/*==============================================================*/ +create table mm +( + kid int not null, + xid int not null, + primary key (kid, xid) +); + +/*==============================================================*/ +/* Table: shangpin */ +/*==============================================================*/ +create table shangpin +( + xid int not null, + sid int not null, + xtype varchar(255), + xprice int, + primary key (xid) +); + +/*==============================================================*/ +/* Table: yuangon */ +/*==============================================================*/ +create table yuangon +( + yid int not null, + sid int not null, + yname varchar(255), + primary key (yid) +); + +/*==============================================================*/ +/* Table: zl */ +/*==============================================================*/ +create table zl +( + yid int not null, + xid int not null, + primary key (yid, xid) +); + +alter table kh add constraint FK_yd foreign key (yid) + references yuangon (yid) on delete restrict on update restrict; + +alter table mm add constraint FK_mm foreign key (kid) + references kh (kid) on delete restrict on update restrict; + +alter table mm add constraint FK_mm2 foreign key (xid) + references shangpin (xid) on delete restrict on update restrict; + +alter table shangpin add constraint FK_shave foreign key (sid) + references chaoshi (sid) on delete restrict on update restrict; + +alter table yuangon add constraint FK_gy foreign key (sid) + references chaoshi (sid) on delete restrict on update restrict; + +alter table zl add constraint FK_zl foreign key (yid) + references yuangon (yid) on delete restrict on update restrict; + +alter table zl add constraint FK_zl2 foreign key (xid) + references shangpin (xid) on delete restrict on update restrict; +INSERT INTO chaoshi (sid,sname)VALUES(1,'永辉超市'); +INSERT INTO kh(kid,kname)VALUES(1,'张三'); +SELECT * FROM chaoshi; diff --git "a/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/\347\254\224\350\256\260.md" "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..fd78358e27235d51ee6b1c279a2c9a03596634ac --- /dev/null +++ "b/\346\270\270\345\230\211\350\261\252/9.3\344\275\234\344\270\232/\347\254\224\350\256\260.md" @@ -0,0 +1,22 @@ +1. 一对一联系(1:1):一个实体的每个实例只关联另一个实体的一个实例。 +2. 一对多联系(1:n):一个实体的每个实例可以关联另一个实体的多个实例 +3. 多对多联系(m:n):两个实体的多个实例之间可以相互关联 + + + + + +三大范式 + +1. **第一范式(1NF)**: + - 数据表中的每一列都必须是原子的,即列中的每个值都是不可再分的基本数据项。 + - 例如,一个表中的某一列不能包含多个值或集合。 +2. **第二范式(2NF)**: + - 在满足第一范式的基础上,要求每个非主属性完全函数依赖于主键,即每个非主属性都必须依赖于整个主键(而不是主键的一部分)。 + - 例如,如果主键是复合主键,那么所有非主属性必须依赖于主键的所有部分。 +3. **第三范式(3NF)**: + - 在满足第二范式的基础上,要求每个非主属性直接依赖于主键,而不是依赖于其他非主属性。 + - 也就是说,消除传递依赖。例如,若A -> B和B -> C,那么应有A -> C,以消除B的依赖关系。 + + +