To avoid redundancy, to save up space, for db strength reasons and to easily add new possible values i designed this db layout:
CREATE TABLE IF NOT EXISTS `tmcc_make` (
`id` tinyint UNSIGNED NOT NULL AUTO_INCREMENT,
`make` varchar(60) NOT NULL UNIQUE,
`status` bit DEFAULT NULL COMMENT 'NULL = active | 1 = deprecated',
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `tmcc_model` (
`id` smallint UNSIGNED NOT NULL AUTO_INCREMENT,
`model` varchar(60) NOT NULL UNIQUE,
`make` tinyint UNSIGNED NOT NULL,
`status` bit DEFAULT NULL COMMENT 'NULL = active | 1 = deprecated',
PRIMARY KEY (`id`),
FOREIGN KEY (`make`) REFERENCES tmcc_make(`id`)
);
CREATE TABLE IF NOT EXISTS `tmcc_vehicle` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`make` tinyint UNSIGNED NOT NULL,
`model` smallint UNSIGNED NOT NULL,
[...]
PRIMARY KEY (`id`),
FOREIGN KEY (`make`) REFERENCES tmcc_make(`id`),
FOREIGN KEY (`model`) REFERENCES tmcc_model(`id`)
);
Now, i know it would be easier to use the description field as PK of the first 2 tables so that i already have those values ready, but this will use a lot of more space. What is the best and less complex way to retreive those strings matching the id? Do you think it will be better to use more space and directly set the strings instead of an integer pk?