-
Notifications
You must be signed in to change notification settings - Fork 0
/
createtable.sql
78 lines (66 loc) · 1.96 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
75
76
77
78
CREATE DATABASE moviedb
CHARACTER SET utf8;
USE moviedb;
CREATE TABLE movies (
id VARCHAR(10) NOT NULL PRIMARY KEY,
title VARCHAR(100) NOT NULL,
year INTEGER NOT NULL,
director VARCHAR(100) NOT NULL,
FULLTEXT (title)
);
CREATE TABLE stars (
id VARCHAR(10) NOT NULL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
birthYear INTEGER
);
CREATE TABLE stars_in_movies (
starId VARCHAR(10) NOT NULL,
FOREIGN KEY(starID) REFERENCES stars(id),
movieId VARCHAR(10) NOT NULL,
FOREIGN KEY(movieId) REFERENCES movies(id)
);
CREATE TABLE genres (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(32) NOT NULL
);
CREATE TABLE genres_in_movies (
genreId INTEGER NOT NULL,
FOREIGN KEY(genreId) REFERENCES genres(id),
movieId VARCHAR(10) NOT NULL,
FOREIGN KEY(movieId) REFERENCES movies(id)
);
CREATE TABLE creditcards (
id VARCHAR(20) NOT NULL PRIMARY KEY,
firstName VARCHAR(50) NOT NULL,
lastName VARCHAR(50) NOT NULL,
expiration DATE NOT NULL
);
CREATE TABLE customers (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
firstName VARCHAR(50) NOT NULL,
lastName VARCHAR(50) NOT NULL,
ccId VARCHAR(20) NOT NULL,
FOREIGN KEY(ccId) REFERENCES creditcards(id),
address VARCHAR(200) NOT NULL,
email VARCHAR(50) NOT NULL,
password VARCHAR(20) NOT NULL
);
CREATE TABLE sales (
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
customerID INTEGER NOT NULL,
FOREIGN KEY(customerID) REFERENCES customers(id),
movieId VARCHAR(10) NOT NULL,
FOREIGN KEY(movieId) REFERENCES movies(id),
saleDate DATE NOT NULL
);
CREATE TABLE ratings (
movieId VARCHAR(10) NOT NULL,
FOREIGN KEY(movieId) REFERENCES movies(id),
rating FLOAT NOT NULL,
numVotes INTEGER NOT NULL
);
CREATE TABLE employees (
email VARCHAR(50) PRIMARY KEY,
password VARCHAR(20) NOT NULL,
fullname VARCHAR(100)
);