-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetupImdbDatabaseWithTables.sql
More file actions
72 lines (63 loc) · 1.66 KB
/
SetupImdbDatabaseWithTables.sql
File metadata and controls
72 lines (63 loc) · 1.66 KB
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
/******************************************************************************************/
-- Queries to create a smaller version of IMDB database
/*****************************************************************************************/
-- Creating and using the database
DROP DATABASE IF EXISTS imdb;
CREATE DATABASE imdb;
USE imdb;
-- Creating the structure of various tables in the database
DROP TABLE IF EXISTS movie;
CREATE TABLE movie
(
id VARCHAR(10) NOT NULL,
title VARCHAR(200) DEFAULT NULL,
year INT DEFAULT NULL,
date_published DATE DEFAULT null,
duration INT,
country VARCHAR(250),
worlwide_gross_income VARCHAR(30),
languages VARCHAR(200),
production_company VARCHAR(200),
PRIMARY KEY (id)
);
DROP TABLE IF EXISTS genre;
CREATE TABLE genre
(
movie_id VARCHAR(10),
genre VARCHAR(20),
PRIMARY KEY (movie_id, genre)
);
DROP TABLE IF EXISTS director_mapping;
CREATE TABLE director_mapping
(
movie_id VARCHAR(10),
name_id VARCHAR(10),
PRIMARY KEY (movie_id, name_id)
);
DROP TABLE IF EXISTS role_mapping;
CREATE TABLE role_mapping
(
movie_id VARCHAR(10) NOT NULL,
name_id VARCHAR(10) NOT NULL,
category VARCHAR(10),
PRIMARY KEY (movie_id, name_id)
);
DROP TABLE IF EXISTS names;
CREATE TABLE names
(
id varchar(10) NOT NULL,
name varchar(100) DEFAULT NULL,
height int DEFAULT NULL,
date_of_birth date DEFAULT null,
known_for_movies varchar(100),
PRIMARY KEY (id)
);
DROP TABLE IF EXISTS ratings;
CREATE TABLE ratings
(
movie_id VARCHAR(10) NOT NULL,
avg_rating DECIMAL(3,1),
total_votes INT,
median_rating INT,
PRIMARY KEY (movie_id)
);