From dba1b94c705704ce6c4d98aebe3375cfb0a60a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E7=BF=94?= <2045602860@qq.com> Date: Thu, 7 Sep 2023 05:34:53 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=BB=BA=2034=20=E5=88=98?= =?UTF-8?q?=E6=99=BA=E7=BF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "34 \345\210\230\346\231\272\347\277\224/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "34 \345\210\230\346\231\272\347\277\224/.keep" diff --git "a/34 \345\210\230\346\231\272\347\277\224/.keep" "b/34 \345\210\230\346\231\272\347\277\224/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 67ba74b18c82bda2859cc45be6d4e7a9c05ca3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E7=BF=94?= <2045602860@qq.com> Date: Thu, 7 Sep 2023 05:35:37 +0000 Subject: [PATCH 2/2] =?UTF-8?q?34=20=E5=88=98=E6=99=BA=E7=BF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘智翔 <2045602860@qq.com> --- ...56\345\272\223\347\273\223\346\236\204.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "34 \345\210\230\346\231\272\347\277\224/\346\225\260\346\215\256\345\272\223\347\273\223\346\236\204.md" diff --git "a/34 \345\210\230\346\231\272\347\277\224/\346\225\260\346\215\256\345\272\223\347\273\223\346\236\204.md" "b/34 \345\210\230\346\231\272\347\277\224/\346\225\260\346\215\256\345\272\223\347\273\223\346\236\204.md" new file mode 100644 index 0000000..86f9120 --- /dev/null +++ "b/34 \345\210\230\346\231\272\347\277\224/\346\225\260\346\215\256\345\272\223\347\273\223\346\236\204.md" @@ -0,0 +1,81 @@ +#### 表与表的关系 + +##### 1.多对多 + +这种情况就要引入第三张表(关系表),将前面两个表的主键当作该表的外键 + +##### 2.一对多 + +将一的主键放到多的当外键 + +##### 3.一对一 + +其中任一表中的主键放到另外一个表当外键 + +## 作业 + +```mysql +-- 删除数据库 +drop database if exists rj ; + +-- 创建 软件工程学院 数据库 +create database if not exists rj charset utf8 ; +-- 选中数据库 +use rj ; + +-- 创建老师表 +create table teacher ( + + t_id int primary key auto_increment, -- 老师编号 + t_name varchar(10) , -- 老师名字 + t_post varchar(10) -- 岗位 + +); + +-- 创建班级表 +create table class ( + + c_id int primary key auto_increment , -- 班级编号 + c_direction varchar(10) , -- 方向 + c_name varchar(10) , -- 班级名称 + t_id int , -- 外键 辅导员编号 + foreign key (t_id) references teacher(t_id) -- 连接老师表 + +); + +-- 创建课程表 +create table syllabus ( + + s_count varchar(10) , -- 节次 + s_id int primary key auto_increment , -- 课程编号 + s_time time , -- 时间 + s_week varchar(10) , -- 星期 + s_name varchar(10) , -- 课程名称 + t_id int , -- 外键 课任老师编号 + c_id int , -- 外键 班级编号 + foreign key (t_id) references teacher(t_id) , -- 连接老师表 + foreign key (c_id) references class(c_id) -- 连接班级表 + +); + +-- 创建学生表 +create table student ( + + s_id int primary key auto_increment , -- 学生编号 + s_name varchar(10) , -- 学生姓名 + c_id int , -- 外键 班级编号 + foreign key (c_id) references class(c_id) -- 连接班级表 + +); + +-- 创建成绩表 +create table score ( + + s_num int , -- 分数 + st_id int , -- 外键 学生编号 + sy_id int , -- 外键 课程编号 + foreign key (sy_id) references syllabus(s_id) ,-- 连接课程表 + foreign key (st_id) references student(s_id) -- 连接学生表 + +); +``` -- Gitee