-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_table.sql
80 lines (67 loc) · 2.09 KB
/
create_table.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
-- noinspection SqlNoDataSourceInspectionForFile
-- noinspection SqlDialectInspectionForFile
CREATE DATABASE IF NOT EXISTS moviedb;
USE moviedb;
CREATE TABLE IF NOT EXISTS movies(
id VARCHAR(10) NOT NULL DEFAULT '',
title VARCHAR(100) NOT NULL DEFAULT '',
year INTEGER NOT NULL,
director VARCHAR(100) NOT NULL DEFAULT '',
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS stars(
id VARCHAR(10) NOT NULL DEFAULT '',
name VARCHAR(100) NOT NULL DEFAULT '',
birthYear INTEGER,
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS stars_in_movies(
starId VARCHAR(10) NOT NULL DEFAULT '',
movieId VARCHAR(10) NOT NULL DEFAULT '',
FOREIGN KEY (starId) REFERENCES stars(id),
FOREIGN KEY (movieId) REFERENCES movies(id)
);
CREATE TABLE IF NOT EXISTS genres(
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS genres_in_movies(
genreId INTEGER NOT NULL,
movieId VARCHAR(10) NOT NULL DEFAULT '',
FOREIGN KEY (genreId) REFERENCES genres(id),
FOREIGN KEY (movieId) REFERENCES movies(id)
);
CREATE TABLE IF NOT EXISTS creditcards(
id VARCHAR(20) NOT NULL DEFAULT '',
firstName VARCHAR(50) NOT NULL DEFAULT '',
lastName VARCHAR(50) NOT NULL DEFAULT '',
expiration DATE NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS customers(
id INTEGER NOT NULL AUTO_INCREMENT,
firstName VARCHAR(50) NOT NULL DEFAULT '',
lastName VARCHAR(50) NOT NULL DEFAULT '',
ccId VARCHAR(20) NOT NULL DEFAULT '',
address VARCHAR(200) NOT NULL DEFAULT '',
email VARCHAR(50) NOT NULL DEFAULT '',
password VARCHAR(20) NOT NULL DEFAULT '',
PRIMARY KEY(id),
FOREIGN KEY(ccId) REFERENCES creditcards(id)
);
CREATE TABLE IF NOT EXISTS sales(
id INTEGER NOT NULL AUTO_INCREMENT,
customerId INTEGER NOT NULL,
movieId VARCHAR(10) NOT NULL DEFAULT '',
saleDate DATE NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(customerId) REFERENCES customers(id),
FOREIGN KEY(movieId) REFERENCES movies(id)
);
CREATE TABLE IF NOT EXISTS ratings(
movieId VARCHAR(10) NOT NULL DEFAULT '',
rating FLOAT NOT NULL,
numVotes INTEGER NOT NULL,
FOREIGN KEY(movieId) REFERENCES movies(id)
);