From 5537cc6fcbafed7ad211a4ba78765671f78ef596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=BD=E6=99=9F=E5=AE=B8?= <11785147+demon-cat-fruit-orange@user.noreply.gitee.com> Date: Tue, 12 Sep 2023 04:21:37 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=2022=20?= =?UTF-8?q?=E6=96=BD=E6=99=9F=E5=AE=B8/20230906.md=20=E4=B8=BA=2022=20?= =?UTF-8?q?=E6=96=BD=E6=99=9F=E5=AE=B8/20230906=E7=AC=94=E8=AE=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230906\347\254\224\350\256\260.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "22 \346\226\275\346\231\237\345\256\270/20230906.md" => "22 \346\226\275\346\231\237\345\256\270/20230906\347\254\224\350\256\260.md" (100%) diff --git "a/22 \346\226\275\346\231\237\345\256\270/20230906.md" "b/22 \346\226\275\346\231\237\345\256\270/20230906\347\254\224\350\256\260.md" similarity index 100% rename from "22 \346\226\275\346\231\237\345\256\270/20230906.md" rename to "22 \346\226\275\346\231\237\345\256\270/20230906\347\254\224\350\256\260.md" -- Gitee From fbdd7e6c938ba06ee3e4c934b8b35ae041cfa2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=BD=E6=99=9F=E5=AE=B8?= <11785147+demon-cat-fruit-orange@user.noreply.gitee.com> Date: Tue, 12 Sep 2023 04:23:14 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=BD=E6=99=9F=E5=AE=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 施晟宸 <11785147+demon-cat-fruit-orange@user.noreply.gitee.com> --- ...03\345\276\227\344\275\234\344\270\232.md" | 132 ++++++++++++++++++ .../20230911\347\224\265\345\275\261.md" | 129 +++++++++++++++++ 2 files changed, 261 insertions(+) create mode 100644 "22 \346\226\275\346\231\237\345\256\270/20230905\345\277\203\345\276\227\344\275\234\344\270\232.md" create mode 100644 "22 \346\226\275\346\231\237\345\256\270/20230911\347\224\265\345\275\261.md" diff --git "a/22 \346\226\275\346\231\237\345\256\270/20230905\345\277\203\345\276\227\344\275\234\344\270\232.md" "b/22 \346\226\275\346\231\237\345\256\270/20230905\345\277\203\345\276\227\344\275\234\344\270\232.md" new file mode 100644 index 0000000..cd99e85 --- /dev/null +++ "b/22 \346\226\275\346\231\237\345\256\270/20230905\345\277\203\345\276\227\344\275\234\344\270\232.md" @@ -0,0 +1,132 @@ +心得 + +1.这节课学习了Visio的用法,在创建数据库之前先使用Visio先建立一个框架,让建立数据库的模型变得简单明了。 + +还学习了数据库中表与表之间的关系 + + 一对一的关系,任意一个表的主键放在另一个表中当外键 + + 一对多的关系,将一的主键放在多的表里当外键 + +多对多的关系,第三张表将前面两张表的主键放在第三张表当外键 + + + +作业 + +```sql +CREATE DATABASE university CHARSET utf8; +SHOW DATABASES; +USE university; + + +#学院 +CREATE TABLE college( + collegeid int NOT NULL PRIMARY KEY, + collegename VARCHAR(8) NOT NULL + ); +INSERT INTO college +VALUES(1,'软件工程学院'); + + + +#专业 +CREATE TABLE profession( + professionid VARCHAR(25) NOT NULL PRIMARY KEY, + professionname VARCHAR(10) NOT NULL, + collegeid int NOT NULL, + foreign key (collegeid) references college (collegeid) + ); +INSERT INTO profession +VALUES("01",'后端',1), + ("02",'新媒体技术',1), + ("03",'前端',1); + + +#班级 + +CREATE TABLE class( + classid int NOT NULL PRIMARY KEY, + classname VARCHAR(10) NOT NULL, + professionid VARCHAR(25) NOT NULL, + FOREIGN KEY (professionid) REFERENCES profession (professionid) + ); + + +INSERT INTO class +VALUES(1,'软件一班',"01"), + (2,'软件二班',"01"), + (3,'软件三班',"02"), + (4,'软件四班',"02"), + (5,'软件五班',"03"), + (6,'软件六班',"03"); + + +#学生 + +CREATE TABLE student( + studentid int NOT NULL PRIMARY KEY, + studentname VARCHAR(8) NOT NULL, + studentsex CHAR(1) NOT NULL, + studentage int NOT NULL, + classid int NOT NULL, + FOREIGN KEY (classid) REFERENCES class (classid) + ); + + +INSERT INTO student +VALUES(10086,'江江','男',8,1), + (10011,'洋洋','女',18,1), + (10056,'晟晟','男',20,2), + (10036,'威威','男',19,3), + (1004410044,'灿灿','女',21,5); + + + +#课程 +CREATE TABLE subject( + subjectid int NOT NULL PRIMARY KEY, + subjectname VARCHAR(25) NOT NULL + ); + + +INSERT INTO subject +VALUES(1111,'MYSQL'), + (2222,'HTML'), + (3333,'JAVA'), + (4444,'python'); + +#老师 +CREATE TABLE teacher( + teacher_id int NOT NULL PRIMARY KEY, + teacher_name VARCHAR(10) NOT NULL, + subject_id int NOT NULL, + FOREIGN KEY (subject_id) REFERENCES subject (subject_id) + ); +INSERT INTO teacher VALUES +(666,'嘿嘿',1111), +(777,'哈哈',2222), +(888,'怕怕',3333), +(999,'哦哦',4444); + +#成绩 +CREATE TABLE exam( + examno char, + studentid int, + MYSQL int, + HTML int, + JAVA int, + python int, + foreign key(studentid) references student(studentid) + ); + INSERT INTO exam VALUES + (1,10086,89,66,96,94), + (2,10011,87,67,96,90), + (3,10056,98,66,96,69), + (4,10036,87,67,87,87), + (5,10036,89,85,99,66); + + + +``` + diff --git "a/22 \346\226\275\346\231\237\345\256\270/20230911\347\224\265\345\275\261.md" "b/22 \346\226\275\346\231\237\345\256\270/20230911\347\224\265\345\275\261.md" new file mode 100644 index 0000000..6878318 --- /dev/null +++ "b/22 \346\226\275\346\231\237\345\256\270/20230911\347\224\265\345\275\261.md" @@ -0,0 +1,129 @@ +今天学习了图书馆数据库系统 + +复习了如何使用ER图来做MySQL数据库。 + +作业 + +```sql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/12 10:51:22 */ +/*==============================================================*/ +CREATE DATABASE movie charset utf8; +use movie; + + +drop table if exists area; + +drop table if exists comments; + +drop table if exists movie; + +drop table if exists type; + +drop table if exists user; + +/*==============================================================*/ +/* Table: area */ +/*==============================================================*/ +create table area +( + area_id int not null auto_increment, + area_name char(5), + primary key (area_id) +); + +INSERT into area VALUES +(1,'中国'), +(2,'英国'), +(3,'俄罗斯'), +(4,'美国'); + +/*==============================================================*/ +/* Table: comments */ +/*==============================================================*/ +create table comments +( + movie_id int, + user_id int, + movie_comments char(50) +); + +INSERT into comments VALUES +(1,2,'哈哈哈哈哈哈哈很好看'), +(1,3,'这真的是一部温柔电影,感谢这被善待的前半生,它存在过。连带着你没有来过的20年'); +INSERT into comments VALUES +(3,1,'类型片八股文,情感铺陈欠缺,人物动机匮乏,表演稍显生涩,药神式转折,故事线只开头不挽结,细节完成度低'); + +/*==============================================================*/ +/* Table: movie */ +/*==============================================================*/ +create table movie +( + movie_id int not null auto_increment, + type_id int, + area_id int, + movie_name char(10), + director char(5), + actor char(50), + language char(5), + begintime date, + movie_time char(5), + score decimal(2,1), + number int, + primary key (movie_id) +); + +INSERT into movie VALUES +(1,5,4,'过往人生','席琳·宋',' 格蕾塔·李 / 刘台午 / 约翰·马加罗 / 文胜雅 / 尹智慧 /','英语/韩语','2023-01-21','106分钟',7.7,15161); +INSERT into movie VALUES +(2,1,4,'巨齿鲨2','本·维特利',' 杰森·斯坦森 / 吴京 / 蔡书雅 / 克利夫·柯蒂斯 /','英语','2023-08-04','119分钟',5.2,57134), +(3,1,1,'八角笼中','王宝强',' 王宝强 / 陈永胜 / 史彭元 / 王迅 / 张祎曈 /','中文','2023-07-06','117分钟',7.4,118071); + +/*==============================================================*/ +/* Table: type */ +/*==============================================================*/ +create table type +( + type_id int not null auto_increment, + type_name char(5), + primary key (type_id) +); +INSERT into type VALUES +(1,'动作'), +(2,'悬疑'), +(3,'恐怖'), +(4,'喜剧'), +(5,'爱情'); + + +/*==============================================================*/ +/* Table: user */ +/*==============================================================*/ +create table user +( + user_id int not null auto_increment, + user_name char(10), + user_ip char(5), + primary key (user_id) +); +INSERT into user VALUES +(1,'哈哈哈哈施层层','福建'), +(2,'哈哈哈哈溜江江','贵州'), +(3,'哈哈哈哈洪洋洋','福建'); + +alter table comments add constraint FK_Relationship_3 foreign key (movie_id) + references movie (movie_id) on delete restrict on update restrict; + +alter table comments add constraint FK_Relationship_4 foreign key (user_id) + references user (user_id) on delete restrict on update restrict; + +alter table movie add constraint FK_Relationship_1 foreign key (type_id) + references type (type_id) on delete restrict on update restrict; + +alter table movie add constraint FK_Relationship_2 foreign key (area_id) + references area (area_id) on delete restrict on update restrict; + + + +``` -- Gitee