-
Notifications
You must be signed in to change notification settings - Fork 0
/
createtable.sql
139 lines (128 loc) · 4.03 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
SET GLOBAL sql_mode = (SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));
DROP DATABASE IF EXISTS `moviedb`;
CREATE DATABASE `moviedb`;
USE moviedb;
DROP TABLE IF EXISTS dbo.movies;
CREATE TABLE `movies`
(
`id` varchar(10) NOT NULL,
`title` varchar(100) NOT NULL,
`year` int NOT NULL,
`director` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT (`title`),
FULLTEXT (`director`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.stars;
CREATE TABLE `stars`
(
`id` varchar(10) NOT NULL,
`name` varchar(100) NOT NULL,
`birthYear` int DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT (`name`),
UNIQUE KEY `id` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.stars_in_movies;
CREATE TABLE `stars_in_movies`
(
`starId` varchar(10) NOT NULL,
`movieId` varchar(10) NOT NULL,
KEY `_idx` (`starId`),
KEY `movieId_idx` (`movieId`),
CONSTRAINT `movieId` FOREIGN KEY (`movieId`) REFERENCES `movies` (`id`),
CONSTRAINT `starId` FOREIGN KEY (`starId`) REFERENCES `stars` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.genres;
CREATE TABLE `genres`
(
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT (`name`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.genres_in_movies;
CREATE TABLE `genres_in_movies`
(
`genreId` int NOT NULL,
`movieId` varchar(10) NOT NULL,
KEY `genreId_idx` (`genreId`),
KEY `movieId_idx` (`movieId`),
CONSTRAINT `genreIdRef` FOREIGN KEY (`genreId`) REFERENCES `genres` (`id`),
CONSTRAINT `movieIdRef` FOREIGN KEY (`movieId`) REFERENCES `movies` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.creditcards;
CREATE TABLE `creditcards`
(
`id` varchar(20) NOT NULL,
`firstName` varchar(50) NOT NULL,
`lastName` varchar(50) NOT NULL,
`expiration` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.customers;
CREATE TABLE `customers`
(
`id` int NOT NULL AUTO_INCREMENT,
`firstName` varchar(50) NOT NULL,
`lastName` varchar(50) NOT NULL,
`ccId` varchar(20) NOT NULL,
`address` varchar(200) NOT NULL,
`email` varchar(50) NOT NULL,
`password` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `creditcardId_idx` (`ccId`),
CONSTRAINT `creditcardId` FOREIGN KEY (`ccId`) REFERENCES `creditcards` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.sales;
CREATE TABLE `sales`
(
`idsales` int NOT NULL AUTO_INCREMENT,
`customerId` int NOT NULL,
`movieId` varchar(10) NOT NULL,
`saleDate` date NOT NULL,
PRIMARY KEY (`idsales`),
KEY `customerIdRef_idx` (`customerId`),
KEY `movieIdRef_idx` (`movieId`),
KEY `customerIdSale_idx` (`customerId`),
KEY `movieIdSale_idx` (`movieId`),
CONSTRAINT `customerIdSale` FOREIGN KEY (`customerId`) REFERENCES `customers` (`id`),
CONSTRAINT `movieIdSale` FOREIGN KEY (`movieId`) REFERENCES `movies` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.ratings;
CREATE TABLE `ratings`
(
`movieId` varchar(10) NOT NULL,
`rating` float NOT NULL,
`numVotes` int NOT NULL,
PRIMARY KEY (`movieId`),
CONSTRAINT `movieIdRating` FOREIGN KEY (`movieId`) REFERENCES `movies` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;
DROP TABLE IF EXISTS dbo.employees;
CREATE TABLE `employees`
(
email varchar(50) primary key,
password varchar(20) not null,
fullname varchar(100)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8
COLLATE = utf8_general_ci;