forked from n8barr/automotive-model-year-data
-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema_normalised_mysql.sql
31 lines (30 loc) · 1.19 KB
/
schema_normalised_mysql.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
DROP TABLE IF EXISTS `year`;
DROP TABLE IF EXISTS `model`;
DROP TABLE IF EXISTS `manufacturer`;
CREATE TABLE `manufacturer` (
`_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`make` VARCHAR(50) NULL,
PRIMARY KEY (`_id`),
UNIQUE `U_manufacturer_make` (`make`),
INDEX `I_manufacturer_make` (`make`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `model` (
`_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`make_id` INT UNSIGNED NOT NULL,
`model` VARCHAR(50) NOT NULL,
PRIMARY KEY (`_id`),
UNIQUE `U_model_make_id_model` (`make_id`,`model`),
FOREIGN KEY (`make_id`) REFERENCES manufacturer(`_id`),
INDEX `I_model_make_id` (`make_id`),
INDEX `I_model_make_id_model` (`make_id`,`model`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `year` (
`_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`year` SMALLINT UNSIGNED NOT NULL,
`model_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`_id`),
UNIQUE `U_year_model_id` (`year`,`model_id`),
FOREIGN KEY (`model_id`) REFERENCES model(`_id`),
INDEX `I_year` (`year`),
INDEX `I_year_model_id` (`year`,`model_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;