-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_dump.sql
115 lines (103 loc) · 2.61 KB
/
schema_dump.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
CREATE TABLE Users (
UID int NOT NULL,
FirstName varchar(255) NOT NULL,
LastName varchar(255) NOT NULL,
Country varchar(2),
ProfilePicture varchar(255),
Email varchar(255) NOT NULL,
Password varchar(255) NOT NULL,
DOB Date,
PRIMARY KEY (UID),
UNIQUE(ProfilePicture)
);
CREATE TABLE Movies (
MID int NOT NULL,
Title varchar(255) NOT NULL,
ReleaseDate Date NOT NULL,
Plot varchar(1023),
Runtime smallint,
Type varchar(255),
Certificate varchar(255) NOT NULL,
PRIMARY KEY (MID)
);
CREATE TABLE People (
PID int NOT NULL,
FirstName varchar(255),
LastName varchar(255),
Gender varchar(1),
DOB Date,
PRIMARY KEY (PID)
);
CREATE TABLE Genres (
MID int NOT NULL,
Name varchar(32) NOT NULL,
FOREIGN KEY (MID) REFERENCES movies(MID),
PRIMARY KEY (MID, Name)
);
CREATE TABLE Posters (
MID int NOT NULL,
FileName varchar(255) NOT NULL,
FOREIGN KEY (MID) REFERENCES movies(MID),
UNIQUE(FileName),
PRIMARY KEY (MID, FileName)
);
CREATE TABLE Photos (
PID int NOT NULL,
FileName varchar(255) NOT NULL,
FOREIGN KEY (PID) REFERENCES people(PID),
UNIQUE(FileName),
PRIMARY KEY (PID, FileName)
);
CREATE TABLE FavGenres (
UID int NOT NULL,
Name varchar(255) NOT NULL,
FOREIGN KEY (UID) REFERENCES Users(UID),
PRIMARY KEY (UID, Name)
);
CREATE TABLE Watched (
UID int NOT NULL,
MID int NOT NULL,
FOREIGN KEY (UID) REFERENCES Users(UID),
FOREIGN KEY (MID) REFERENCES Movies(MID),
PRIMARY KEY (UID, MID)
);
CREATE TABLE Liked (
UID int NOT NULL,
MID int NOT NULL,
FOREIGN KEY (UID) REFERENCES Users(UID),
FOREIGN KEY (MID) REFERENCES Movies(MID),
PRIMARY KEY (UID, MID)
);
CREATE TABLE CreatedBy (
PID int NOT NULL,
MID int NOT NULL,
FOREIGN KEY (PID) REFERENCES People(PID),
FOREIGN KEY (MID) REFERENCES Movies(MID),
PRIMARY KEY (PID, MID)
);
CREATE TABLE Reviews (
UID int NOT NULL,
MID int NOT NULL,
Date Date NOT NULL,
Stars tinyint NOT NULL,
Content varchar(1023),
FOREIGN KEY (UID) REFERENCES Users(UID),
FOREIGN KEY (MID) REFERENCES Movies(MID),
PRIMARY KEY (UID, MID)
);
CREATE TABLE Cast (
MID int NOT NULL,
PID int NOT NULL,
CharacterName varchar(255) NOT NULL,
FOREIGN KEY (MID) REFERENCES Movies(MID),
FOREIGN KEY (PID) REFERENCES People(PID),
PRIMARY KEY (MID, PID)
);
CREATE TABLE Crew (
MID int NOT NULL,
PID int NOT NULL,
Role varchar(255) NOT NULL,
FOREIGN KEY (MID) REFERENCES Movies(MID),
FOREIGN KEY (PID) REFERENCES People(PID),
PRIMARY KEY (MID, PID)
);