This repository has been archived by the owner on Feb 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatetable.sql
74 lines (65 loc) · 2.08 KB
/
createtable.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
DROP DATABASE IF EXISTS moviedb;
CREATE DATABASE moviedb;
USE moviedb;
CREATE TABLE IF NOT EXISTS movies(
id VARCHAR(10) NOT NULL DEFAULT '',
title VARCHAR(100) NOT NULL DEFAULT '',
year INT 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 INT DEFAULT NULL,
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 INT NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS genres_in_movies(
genreId INT 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 INT 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 INT NOT NULL AUTO_INCREMENT,
customerId INT 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 INT NOT NULL
);