-- 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='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema EstudanteDisciplina
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `EstudanteDisciplina` ;

-- -----------------------------------------------------
-- Schema EstudanteDisciplina
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `EstudanteDisciplina` DEFAULT CHARACTER SET utf8 ;
USE `EstudanteDisciplina` ;

-- -----------------------------------------------------
-- Table `EstudanteDisciplina`.`Estudante`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `EstudanteDisciplina`.`Estudante` (
  `CPF` INT NOT NULL,
  `Nome` VARCHAR(45) NULL,
  `NumMatricula` CHAR(11) NULL,
  PRIMARY KEY (`CPF`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `EstudanteDisciplina`.`Telefone`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `EstudanteDisciplina`.`Telefone` (
  `idAluno` INT NOT NULL,
  `Telefone` VARCHAR(45) NULL,
  `Estudante_CPF` INT NOT NULL,
  PRIMARY KEY (`idAluno`, `Estudante_CPF`),
  INDEX `fk_Telefone_Estudante1_idx` (`Estudante_CPF` ASC),
  CONSTRAINT `fk_Telefone_Estudante1`
    FOREIGN KEY (`Estudante_CPF`)
    REFERENCES `EstudanteDisciplina`.`Estudante` (`CPF`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `EstudanteDisciplina`.`Disciplina`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `EstudanteDisciplina`.`Disciplina` (
  `idDisciplina` INT NOT NULL,
  `Nome` VARCHAR(45) NULL,
  `DepID` INT NULL,
  PRIMARY KEY (`idDisciplina`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `EstudanteDisciplina`.`Disciplina_has_Estudante`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `EstudanteDisciplina`.`Disciplina_has_Estudante` (
  `Disciplina_idDisciplina` INT NOT NULL,
  `Estudante_CPF` INT NOT NULL,
  PRIMARY KEY (`Disciplina_idDisciplina`, `Estudante_CPF`),
  INDEX `fk_Disciplina_has_Estudante_Estudante1_idx` (`Estudante_CPF` ASC),
  INDEX `fk_Disciplina_has_Estudante_Disciplina1_idx` (`Disciplina_idDisciplina` ASC),
  CONSTRAINT `fk_Disciplina_has_Estudante_Disciplina1`
    FOREIGN KEY (`Disciplina_idDisciplina`)
    REFERENCES `EstudanteDisciplina`.`Disciplina` (`idDisciplina`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Disciplina_has_Estudante_Estudante1`
    FOREIGN KEY (`Estudante_CPF`)
    REFERENCES `EstudanteDisciplina`.`Estudante` (`CPF`)
    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;
