From af25c7b8c3e0b31980a9d585f3d805da64d86cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E9=91=AB?= <11785109+linxin221@user.noreply.gitee.com> Date: Tue, 12 Sep 2023 03:59:36 +0000 Subject: [PATCH] =?UTF-8?q?02=E6=9E=97=E9=91=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 林鑫 <11785109+linxin221@user.noreply.gitee.com> --- .../20230911\347\224\265\345\275\261.md" | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 "02 \346\236\227\351\221\253/20230911\347\224\265\345\275\261.md" diff --git "a/02 \346\236\227\351\221\253/20230911\347\224\265\345\275\261.md" "b/02 \346\236\227\351\221\253/20230911\347\224\265\345\275\261.md" new file mode 100644 index 0000000..7bf6191 --- /dev/null +++ "b/02 \346\236\227\351\221\253/20230911\347\224\265\345\275\261.md" @@ -0,0 +1,129 @@ +今天学习了图书馆数据库系统具体的框架做法,进一步学习到了数据库模型构造的思维。 + + + +作业 + +```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