-
Notifications
You must be signed in to change notification settings - Fork 4
/
schema.sql
66 lines (55 loc) · 1.35 KB
/
schema.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
--------------------------------
-- Based on the exported file from QuickDBD: https://www.quickdatabasediagrams.com/
drop table if exists genre_anime;
drop table if exists rating;
drop table if exists genre;
drop table if exists source_site;
drop table if exists anime;
create table "anime" (
"id" serial primary key,
"title" varchar,
"episodes" int
);
create table "source_site" (
"id" serial primary key,
"source_name" varchar
);
create table "genre" (
"id" serial primary key,
"genre_name" varchar
);
create table "rating" (
"id" serial primary key,
"id_anime" int,
"id_source" int,
"rating" int,
foreign key("id_anime")
references "anime" ("id"),
foreign key("id_source")
references "source_site" ("id")
);
create table "genre_anime" (
"id_anime" int,
"id_genre" int,
foreign key("id_anime")
references "anime" ("id"),
foreign key("id_genre")
references "genre" ("id")
);
--------------------------------
-- Added source_site values manually
insert into source_site (source_name)
values ('Crunchyroll'),
('MyAnimeList');
--------------------------------
-- Query ran to verify information
select
a.title,
ss.source_name,
r.rating
from anime a
left join rating r
on a.id = r.id_anime
left join source_site ss
on r.id_source = ss.id
where source_name = 'Crunchyroll';