-- MySQL Script generated by MySQL Workbench
-- Fri Sep  5 09:18:27 2025
-- Model: New Model    Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `Member`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Member` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `memberNumber` INT NOT NULL,
  `fullName` VARCHAR(128) NOT NULL,
  `gender` CHAR(1) NOT NULL,
  `birthDate` DATE NOT NULL,
  `realAdress` VARCHAR(128) NOT NULL,
  `postAddress` VARCHAR(128) NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `Genre`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Genre` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `Movie`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Movie` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `cost` INT NOT NULL,
  `duration` INT NOT NULL,
  `genreId` INT NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_Movie_Genre_idx` (`genreId` ASC) VISIBLE,
  CONSTRAINT `fk_Movie_Genre`
    FOREIGN KEY (`genreId`)
    REFERENCES `Genre` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `MemberMovie`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `MemberMovie` (
  `MemberId` INT NOT NULL,
  `MovieId` INT NOT NULL,
  PRIMARY KEY (`MemberId`, `MovieId`),
  INDEX `fk_MemberMovie_Movie1_idx` (`MovieId` ASC) VISIBLE,
  INDEX `fk_MemberMovie_Member1_idx` (`MemberId` ASC) VISIBLE,
  CONSTRAINT `fk_MemberMovie_Member1`
    FOREIGN KEY (`MemberId`)
    REFERENCES `Member` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_MemberMovie_Movie1`
    FOREIGN KEY (`MovieId`)
    REFERENCES `Movie` (`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;
