diff --git "a/04\345\220\264\350\211\257\347\241\274/20230911\350\261\206\347\223\243.md" "b/04\345\220\264\350\211\257\347\241\274/20230911\350\261\206\347\223\243.md" new file mode 100644 index 0000000000000000000000000000000000000000..a9a840701ee734ab9cb8ce05d48ccbe5e7323429 --- /dev/null +++ "b/04\345\220\264\350\211\257\347\241\274/20230911\350\261\206\347\223\243.md" @@ -0,0 +1,270 @@ +笔记: + +天气:很好 + +复习 + +完成豆瓣mysql + + + +```mysql +#建立数据库movie +create database movie charset utf8; +#使用数据库movie +use movie; +#如果各表存在删除各表 +drop table if exists Mark; + +drop table if exists Otherfilms; + +drop table if exists country; + +drop table if exists html; + +drop table if exists job; + +drop table if exists language; + +drop table if exists movie; + +drop table if exists movieaward; + +drop table if exists moviepeople; + +drop table if exists photo; + +drop table if exists type; + +drop table if exists user; + +drop table if exists video; + +drop table if exists yfqk; + +#建立评分表 +create table Mark +( + m_id int not null, + m_mark float not null, + m_wuxing float not null, + m_sixing float not null, + m_sanxing float not null, + m_erxing float not null, + m_yixing float not null +); +#插入测试数据 +insert into Mark values (1,7.7,20.6,46.9,28.2,3.6,0.7); +#建立相关电影表 +create table Otherfilms +( + of_id int not null auto_increment, + m_id int not null, + of_name char(50) not null, + primary key (of_id) +); +#插入测试数据 +insert into Otherfilms values (1,1,'冰山的阴影'); + +#建立国家表 +create table country +( + c_id int(0) not null auto_increment, + m_id int not null, + c_name char(20) not null, + primary key (c_id) +); +#插入测试数据 +insert into country values +(null,1,'美国'), +(null,1,'韩国'); + +#建立网页表 +create table html +( + ip int not null auto_increment, + m_id int not null, + html_name char(20) not null, + primary key (ip) +); +#插入测试数据 +insert into html values (1,1,'豆瓣电影网'); +#建立职位表 +create table job +( + j_id int not null auto_increment, + mp_id int not null, + j_name char(20) not null, + primary key (j_id) +); +insert into job values +(null,1,'导演'), +(null,1,'编剧'), +(null,2,'主演'), +(null,3,'主演'), +(null,4,'主演'), +(null,5,'主演'), +(null,6,'主演'); + + + +#建立语言表 +create table language +( + l_id int not null auto_increment, + m_id int not null, + l_name char(20) not null, + primary key (l_id) +); +#插入测试数据 +insert into language values +(null,1,'中文'), +(null,1,'英文'), +(null,1,'韩文'), +(null,1,'俄语'); + +#建立电影表 +create table movie +( + m_id int not null auto_increment, + m_name char(20) not null, + m_time time not null, + m_nameother char(20) not null, + m_opentime datetime not null, + m_IMDB char(20) not null, + m_introduction char(100) not null, + primary key (m_id) +); +insert into movie values + (1,'过往人生','01:46:00','前世姻缘,前度人生,前世因缘','2023-01-21 00:00:00','tt13238346','这是爱情片很好看,很棒'); + +#建立电影获奖表 +create table movieaward +( + ma_id int not null auto_increment, + m_id int not null, + ma_name char(20) not null, + primary key (ma_id) +); +insert into movieaward values + (null,1,'第73届柏林电影节'), + (null,1,'金熊奖'); + +#建立电影人表 +create table moviepeople +( + mp_id int not null auto_increment, + m_id int not null, + mp_name char(20) not null, + primary key (mp_id) +); +insert into moviepeople values +(null,1,'席琳.宋'), +(null,1,'格蕾塔.李'), +(null,1,'刘台午'), +(null,1,'约翰.马加罗'), +(null,1,'文胜雅'), +(null,1,'尹智慧'); + +#建立相关图片表 +create table photo +( + p_id int not null auto_increment, + m_id int not null, + p_name char(20) not null, + primary key (p_id) +); +#插入测试数据 +insert into photo values (1,1,'精彩片段截图'); +#建立电影类型表 +create table type +( + t_id int not null auto_increment, + m_id int not null, + t_name char(20) not null, + primary key (t_id) +); +#插入测试数据 +insert into type values +(null,1,'爱情'), +(null,1,'剧情'); + +#建立豆瓣观众表 +create table user +( + u_id int not null auto_increment, + m_id int not null, + u_name char(20) not null, + u_uers char(20) not null, + u_pwd char(20) not null, + u_daunping char(255) not null, + u_yingping char(255) not null, + primary key (u_id) +); +#插入测试数据 +insert into user values (null,1,'猪猪侠','zzx','zzxxxs','很好看','电影剧情好'); + +#建立相关视频表 +create table video +( + v_id int not null auto_increment, + m_id int not null, + v_name char(20) not null, + primary key (v_id) +); +#插入测试数据 +insert into video values (null,1,'电影预告片'); + +#建立电影风评表 +create table yfqk +( + m_id int not null, + yf_pepole int not null, #评论人数 + yf_people int not null, #评分人数 + yf_hot char(255) not null, + yf_new char(255) not null +); +#插入测试数据 +insert into yfqk values (1,14859,30669,'真好看,太感动了','最新评论很好看'); + +alter table Mark add constraint FK_movie_mark2 foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table Otherfilms add constraint FK_of_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table country add constraint FK_country_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table html add constraint FK_html_moive foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table job add constraint FK_mp_job foreign key (mp_id) + references moviepeople (mp_id) on delete restrict on update restrict; + +alter table language add constraint FK_language_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table movieaward add constraint FK_ma_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table moviepeople add constraint FK_people_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table photo add constraint FK_photo_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table type add constraint FK_movie_type foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table user add constraint FK_watch_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table video add constraint FK_movie_video foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; + +alter table yfqk add constraint FK_score_movie foreign key (m_id) + references movie (m_id) on delete restrict on update restrict; +``` + + 1694429280024.png