From cf303def108d84c1b6b22b5d97d6e83d4c25dc6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8F=AD=E9=98=B3=E4=B8=BD?= <2431466589@qq.com> Date: Thu, 7 Sep 2023 12:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\346\254\241\344\275\234\344\270\232.md" | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 "37 \346\217\255\351\230\263\344\270\275/20230906 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" diff --git "a/37 \346\217\255\351\230\263\344\270\275/20230906 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" "b/37 \346\217\255\351\230\263\344\270\275/20230906 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000..66dd441 --- /dev/null +++ "b/37 \346\217\255\351\230\263\344\270\275/20230906 \347\254\254\344\270\200\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,160 @@ +## 笔记 + +### 数据库 +关系是相互的,一个学生,可以选多个课,课也可以被多个学生选(多对多)这种关系应借助第三个表进行关联,将前面两张表的主键当作外键表与表的关系:1对1,1对多,多对多 +1对多:第二张的表的主键当另一个表的外键(多) +(1) 当1对1:将其中任一表的主键放在另一张表中的外键 +头脑风暴:院系、专业、班级、学生,教师、谢程、深程表、教室visio +链头变上有一个号数据库chen's +数据库设计方法 按住(f11,再抢动,可复制 +1.直观设计法 选中,一直抢动,不能点击 +2.规范设计法 多对多,用字日表行N.M… +3.算机辅助设计法 +E-R图(实体关系图) +3要表:实体(表)、属性(字段)和关系(类似外键约束) +实体:用矩形.主键:加下划线 外键:横线中间加菱形 + + + +### mysql + +``` mysql +CREATE DATABASE yangyang charset utf8; +use yangyang; +##学院表 +CREATE table college( +collegeName VARCHAR(12), +collegeId int PRIMARY key +); + +##专业表 +CREATE TABLE major( +majorId int PRIMARY key, +majorName VARCHAR(12), +collegeId int, +foreign KEY (collegeId) references college(collegeId) +); + +##班级表 +CREATE TABLE class( +classId int PRIMARY key, +className VARCHAR(12), +majorId int, +foreign KEY (majorId) references major(majorId) +); +#3教室表 +CREATE TABLE classroom( +classroomId int PRIMARY key , +classroomAddress VARCHAR(12), +classroomName VARCHAR(12) +); + +##教师表 +CREATE TABLE teacher( +teacherId int PRIMARY key, +teacherName VARCHAR(12), +courseld int +); +DROP TABLE student; + +##学生表 +CREATE TABLE student( +studentId int PRIMARY key, +studentName VARCHAR(12), +sex CHAR, +courseId int +); +drop TABLE course; +## 课程表 +CREATE TABLE course( +courseId int PRIMARY key, +courseName VARCHAR(12), +classroomId int, +teacherId int, +studentId int, +classId int, +foreign KEY (classId) references class(classId), +foreign KEY (classroomId) references classroom(classroomId), +foreign KEY (teacherId) references teacher(teacherId), +foreign KEY (studentId) references student(studentId) +); + +``` + + + +```mysql +CREATE DATABASE yangyang charset utf8; +use yangyang; +##学院表 +CREATE table college( +collegeName VARCHAR(12), +collegeId int PRIMARY key +); + +INSERT into college VALUES + ('软件工程学院',1), + ('信息技术学院',2), + ('软件工程学院',3); + + +##专业表 +CREATE TABLE major( +majorId int PRIMARY key, +majorName VARCHAR(12), +collegeId int, +foreign KEY (collegeId) references college(collegeId) +); + +INSERT into major VALUES +(1,'软件技术',1), +(2,'软件技术',2), +(3,'软件技术',3); + +##班级表 +CREATE TABLE class( +classId int PRIMARY key, +className VARCHAR(12), +majorId int, +foreign KEY (majorId) references major(majorId) +); +#3教室表 +CREATE TABLE classroom( +classroomId int PRIMARY key , +classroomAddress VARCHAR(12), +classroomName VARCHAR(12) +); + +##教师表 +CREATE TABLE teacher( +teacherId int PRIMARY key, +teacherName VARCHAR(12), +courseld int +); +DROP TABLE student; + +##学生表 +CREATE TABLE student( +studentId int PRIMARY key, +studentName VARCHAR(12), +sex CHAR, +courseId int +); +drop TABLE course; +## 课程表 +CREATE TABLE course( +courseId int PRIMARY key, +courseName VARCHAR(12), +classroomId int, +teacherId int, +studentId int, +classId int, +foreign KEY (classId) references class(classId), +foreign KEY (classroomId) references classroom(classroomId), +foreign KEY (teacherId) references teacher(teacherId), +foreign KEY (studentId) references student(studentId) +); + + +``` + -- Gitee