-
Notifications
You must be signed in to change notification settings - Fork 2
/
starter_queries.sql
209 lines (188 loc) · 5.1 KB
/
starter_queries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
CREATE DATABASE mwdb;
CREATE TABLE celebrity(
person_id varchar(10) PRIMARY KEY,
firstname varchar(20) NOT NULL,
lastname varchar(20) NOT NULL,
birthyear int,
age int,
gender varchar(10)
);
CREATE TABLE Production_company(
company_name varchar(50) PRIMARY KEY,
headquarter varchar(40)
);
alter table Production_company add column total_produced int;
do
$$
DECLARE
r_prod record;
begin
for r_prod in select * from movie_produced_by loop
update Production_company set total_produced = total_produced+1
where company_name =r_prod.company_name;
end loop;
end;
$$;
CREATE TABLE ott_platform(
platform_name varchar(20) Primary KEY
);
alter table ott_platform add column total int;
CREATE TABLE movie(
movie_id varchar(10) PRIMARY KEY,
title varchar(60) NOT NULL,
production_cost float,
rating float CHECK(rating>0 and rating <=10),
rated varchar(10),
release_date Date,
platform varchar(20),
likes int,
runtime int,
director varchar(10),
CONSTRAINT fk_movie_director
FOREIGN KEY (director) REFERENCES celebrity(person_id),
CONSTRAINT fk_movie_platform
FOREIGN KEY (platform) REFERENCES ott_platform(platform_name)
);
CREATE TABLE movie_genre(
movie_id varchar(10),
genre varchar(10),
FOREIGN KEY (movie_id) REFERENCES movie(movie_id),
PRIMARY KEY (movie_id, genre)
);
CREATE TABLE db_user(
email varchar(50) PRIMARY KEY,
username varchar(20) UNIQUE,
date_of_birth DATE,
firstname varchar(20) NOT NULL,
lastname varchar(20) NOT NULL,
hash varchar(100) NOT NULL,
warning int
);
CREATE TABLE blocked_user(
email varchar(50) PRIMARY KEY
);
CREATE TABLE movie_review(
review_id varchar(10) PRIMARY KEY,
posted_on Date,
content varchar(1000),
up_votes int,
movie_id varchar(10),
username varchar(20),
CONSTRAINT fk_review_movie_id
FOREIGN KEY (movie_id) REFERENCES movie(movie_id),
CONSTRAINT fk_review_username
FOREIGN KEY (username) REFERENCES db_user(username)
);
CREATE TABLE movie_produced_by(
company_name varchar(50),
movie_id varchar(10),
PRIMARY KEY (company_name, movie_id),
CONSTRAINT fk_movie_company
FOREIGN KEY (company_name) REFERENCES Production_company(company_name),
CONSTRAINT fk_produced_movie_id
FOREIGN KEY (movie_id) REFERENCES movie(movie_id)
);
CREATE TABLE movie_cast(
movie_id varchar(10),
person_id varchar(10),
role varchar(40),
PRIMARY KEY (movie_id, person_id, role),
CONSTRAINT fk_cast_movie_id
FOREIGN KEY (movie_id) REFERENCES movie(movie_id),
CONSTRAINT fk_cast_person_id
FOREIGN KEY (person_id) REFERENCES celebrity(person_id)
);
CREATE TABLE tv_show(
show_id varchar(10) PRIMARY KEY,
title varchar(40) NOT NULL,
rating float CHECK(rating>0 and rating <=10),
rated varchar(20),
seasons int,
release_year int,
end_year int CHECK(release_year<end_year),
platform varchar(20),
CONSTRAINT fk_tv_platform
FOREIGN KEY (platform) REFERENCES ott_platform(platform_name)
);
CREATE TABLE show_review(
review_id varchar(10) PRIMARY KEY,
posted_on Date,
content varchar(1000),
up_votes int,
show_id varchar(10),
username varchar(20),
CONSTRAINT fk_review_show_id
FOREIGN KEY (show_id) REFERENCES tv_show(show_id),
CONSTRAINT fk_show_review_username
FOREIGN KEY (username) REFERENCES db_user(username)
);
CREATE TABLE show_genre(
show_id varchar(10),
genre varchar(10),
FOREIGN KEY (show_id) REFERENCES tv_show(show_id),
PRIMARY KEY (show_id, genre)
);
CREATE TABLE show_produced_by(
company_name varchar(50),
show_id varchar(10),
PRIMARY KEY (company_name, show_id),
CONSTRAINT fk_tv_company
FOREIGN KEY (company_name) REFERENCES Production_company(company_name),
CONSTRAINT fk_producer_show
FOREIGN KEY (show_id) REFERENCES tv_show(show_id)
);
CREATE TABLE show_cast(
show_id varchar(10),
person_id varchar(10),
role varchar(40),
PRIMARY KEY (show_id, person_id, role),
CONSTRAINT fk_cast_show_id
FOREIGN KEY (show_id) REFERENCES tv_show(show_id),
CONSTRAINT fk_cast_person_id
FOREIGN KEY (person_id) REFERENCES celebrity(person_id)
);
CREATE TABLE filtered_movies(
movie_id varchar(10)
);
CREATE TABLE wishlist(
username varchar(20),
movie_id varchar(10)
);
CREATE TABLE genre_rating(
genre varchar(20),
rating float
);
CREATE TABLE ott_rating(
platform varchar(40),
rating float,
total int
);
CREATE TABLE abusive_words(
words varchar(20)
);
CREATE TABLE liked_movies(
movie_id varchar(10),
username varchar(20)
);
CREATE TABLE upvoted_reviews(
review_id varchar(10),
username varchar(20)
);
DROP TABLE show_cast;
DROP TABLE show_produced_by;
DROP TABLE movie_review;
DROP TABLE show_review;
DROP TABLE movie_cast;
DROP TABLE movie_produced_by;
DROP TABLE review;
DROP TABLE db_user;
DROP TABLE db_user;
DROP TABLE Production_company;
DROP TABLE Person;
DROP TABLE show_genre;
DROP TABLE movie_genre;
DROP TABLE tv_show;
DROP TABLE movie;
DROP TABLE ott_platform;
DROP TABLE abusive_words;
DROP TABLE celebrity;