diff --git "a/37 \351\227\253\351\233\252\350\216\262/20230904.md" "b/37 \351\227\253\351\233\252\350\216\262/20230904.md" new file mode 100644 index 0000000000000000000000000000000000000000..2d06c2ead19f5f9ef8760aa00b7540624878c0bb --- /dev/null +++ "b/37 \351\227\253\351\233\252\350\216\262/20230904.md" @@ -0,0 +1,3 @@ +## 日记 + +#### 随着大二课程的开始,Mysql课程的难度直线上升,让我觉得学好这门课是不容易的,MySQL数据库的应用范围非常广泛,学好这门课程就显得尤为重要。总而言之,之前学习MySQL数据库学习让我受益匪浅,让我懂得了自主学习,和向他人学习的好处,之后我会努力学习并加深了我对于MySQL数据库的理解,能够更加熟练的掌握MySQL数据库的基本语法和使用方法。 \ No newline at end of file diff --git "a/37 \351\227\253\351\233\252\350\216\262/20230905 \346\225\260\346\215\256\345\272\223\346\237\245\350\257\242.md" "b/37 \351\227\253\351\233\252\350\216\262/20230905 \346\225\260\346\215\256\345\272\223\346\237\245\350\257\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..ec1eb3773af2eeb347df3f02f90df36bf325b923 --- /dev/null +++ "b/37 \351\227\253\351\233\252\350\216\262/20230905 \346\225\260\346\215\256\345\272\223\346\237\245\350\257\242.md" @@ -0,0 +1,140 @@ +## 一,笔记 + +表之间的关系 + +1.一对一的关系:将其中任意一个表的主键放在另一个表中当外键 + +2.一对多的关系:将一的主键放在多的表中当外键 + +3.多对多的关系:必须第三张表,将前面两张表的主键放在第三张表当外键 + +ER图:实体关系图 + + 三要素:实体,属性,关系 + +## 二,作业 + +```sql +create DATABASE off charset utf8; + +use off; + +-- 院系表 +create table college( +col_id int PRIMARY key, +col_name varchar(10) +); + +insert into college values +(1,'软件工程学院'); + + +-- 专业表 +create table profe( +profe_id int PRIMARY key, +profe_name varchar(10), +col_id int, +FOREIGN key(col_id) REFERENCES college(col_id) +); + +insert into profe values +(1,'软件技术',1); + +-- 班级表 +create table class( +class_id int PRIMARY key, +class_name varchar(10), +profe_id int, +FOREIGN key(profe_id) REFERENCES profe(profe_id) +); + +insert into class values +(1,'后端一班',1), +(2,'前端二班',1), +(3,'新媒体三班',1); + + +-- 学生表 +create table student( +student_id int PRIMARY key, +student_name varchar(10), +class_id int, +FOREIGN key(class_id) REFERENCES class(class_id) +); + +insert into student values +(1,'小李',1), +(2,'小王',2), +(3,'小张',3); + +-- 课程 +create table couse( +couse_id int PRIMARY key, +couse_name varchar(10) +); + +insert into couse values +(1,'JAVA'), +(2,'MYSQL'), +(3,'PS'); + +-- 选修表 +create table elec( +couse_id int, +couse int, +student_id int, +FOREIGN key(student_id) REFERENCES student(student_id), +FOREIGN key(couse_id) REFERENCES couse(couse_id) +); + + +insert into elec values +(1,90,1), +(2,100,2), +(3,95,3); + + +-- 课程表 +create table kecheng( +kecheng_time varchar(10), +class_id int, +address varchar(20) PRIMARY key, +FOREIGN key(class_id) REFERENCES class(class_id) +); + + +insert into kecheng values +('周二',2,'望云楼'), +('周四',1,'良才楼'), +('周五',3,'大讲堂'); + +-- 教师表 +create table teacher( +teacher_id int, +teacher_name varchar(10), +couse_id int, +FOREIGN key(couse_id) REFERENCES couse(couse_id) +); + +insert into teacher values +(1,'邱邱',1), +(2,'冰冰',2), +(3,'丽丽',3); +-- 教室表 +create table address( +address_id int, +address varchar(20), +FOREIGN key(address) REFERENCES kecheng(address) +); + +insert into address values +(1,'望云楼'), +(2,'良才楼'), +(3,'大讲堂'); + +-- 查询教小李同学的老师的姓名 +select te.teacher_name from college c,profe p,class cl,student s,elec el,couse co,kecheng ke,teacher te where c.col_id=p.col_id and cl.profe_id=p.profe_id and s.class_id=s.class_id and el.student_id=s.student_id and el.couse_id=co.couse_id and ke.class_id=s.class_id and te.couse_id=co.couse_id and s.student_name='小李'; + + +``` +