I'm designing a database for an exercise for class and am stuck in the design. In inventory system there are DVD's (divided into 3 Categories: TV, Music Vid, Movie). Within each of those categories it has its own subset of information - TV Category Info: TVInfo1, TVInfo2, TVInfo3 ; Movies Category: MInfo1, MInfo2, MInfo3, MInfo4 ; Music Video Category: MVInfo 1, MVInfo2.
I'm unsure how to incorporate that the Category Type has its own unique attributes dependent on each category. For my tables so far:
DVD(Title [PK], CategoryID[FK])
Category(CategoryID[PK], TYPE)
CatMovie(Title [PK,FK], CategoryID[PK,FK], MInfo1, MInfo2, MInfo3, MInfo4)
CatMV(Title [PK,FK], CategoryID[PK,FK],MVInfo 1, MVInfo2)
CatTV(Title [PK,FK], CategoryID[PK,FK],TVInfo1, TVInfo2, TVInfo3)
Not sure if that seems right. Thank you for any help.
As I can see, its just a simple database for a library of films. You can have design like this:
Now, following your specs, your title_mstr
table contains all your titles. The title_category
table will contain your categories( Movie
or TV
). Then your info per category would be in category_info
with reference to the title_category
. This schema also includes a foreign key for each.
Here's the code:
-- -----------------------------------------------------
-- Table `title_category`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `title_category` (
`title_cat_id` INT NOT NULL,
`title_category_desc` VARCHAR(45) NULL,
PRIMARY KEY (`title_cat_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `title_mstr`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `title_mstr` (
`title_id` INT NOT NULL AUTO_INCREMENT,
`title_cat_id` INT NULL,
`title_name` VARCHAR(100) NOT NULL,
`title_desc` VARCHAR(45) NULL,
`title_details` VARCHAR(45) NULL,
PRIMARY KEY (`title_id`),
UNIQUE INDEX `movie_name_UNIQUE` (`title_name` ASC),
INDEX `title_cat_id_idx` (`title_cat_id` ASC),
CONSTRAINT `title_cat_id`
FOREIGN KEY (`title_cat_id`)
REFERENCES `title_category` (`title_cat_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `tape`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tape` (
`tape_id` INT NOT NULL,
`tape_category_id` INT NULL,
`movie_id` INT NULL,
`tape_details` VARCHAR(45) NULL,
PRIMARY KEY (`tape_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `title_category_info`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `title_category_info` (
`title_category_info_id` INT NOT NULL AUTO_INCREMENT,
`title_cat_id` INT NULL,
`title_category_info` VARCHAR(45) NULL,
PRIMARY KEY (`title_category_info_id`),
INDEX `title_cat_id_idx` (`title_cat_id` ASC),
CONSTRAINT `title_cat_id`
FOREIGN KEY (`title_cat_id`)
REFERENCES `title_category` (`title_cat_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
For better understanding, you may refer to this link:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.