-- MySQL Script generated by MySQL Workbench
-- 02/03/18 16:48:31
-- 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='TRADITIONAL,ALLOW_INVALID_DATES';

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

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

-- -----------------------------------------------------
-- Table `mydb`.`Etudiant`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Etudiant` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Etudiant` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `nom` VARCHAR(45) NOT NULL,
  `prenom` VARCHAR(45) NOT NULL,
  `diplome` VARCHAR(45) NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Matiere`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Matiere` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Matiere` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `nom` VARCHAR(45) NULL,
  `nbHeure` INT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Professeur`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Professeur` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Professeur` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `nom` VARCHAR(45) NOT NULL,
  `prenom` VARCHAR(45) NOT NULL,
  `competence` VARCHAR(45) NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Cours`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Cours` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Cours` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `salle` VARCHAR(45) NULL,
  `horaire` DATETIME NULL,
  `idMatiere` INT NOT NULL,
  `idProfesseur` INT NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_Cours_Matiere_idx` (`idMatiere` ASC),
  INDEX `fk_Cours_Professeur1_idx` (`idProfesseur` ASC),
  CONSTRAINT `fk_Cours_Matiere`
    FOREIGN KEY (`idMatiere`)
    REFERENCES `mydb`.`Matiere` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Cours_Professeur1`
    FOREIGN KEY (`idProfesseur`)
    REFERENCES `mydb`.`Professeur` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Participant`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Participant` ;

CREATE TABLE IF NOT EXISTS `mydb`.`Participant` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `place` INT NOT NULL,
  `idCours` INT NOT NULL,
  `idEtudiant` INT NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_Participant_Cours1_idx` (`idCours` ASC),
  INDEX `fk_Participant_Etudiant1_idx` (`idEtudiant` ASC),
  CONSTRAINT `fk_Participant_Cours1`
    FOREIGN KEY (`idCours`)
    REFERENCES `mydb`.`Cours` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Participant_Etudiant1`
    FOREIGN KEY (`idEtudiant`)
    REFERENCES `mydb`.`Etudiant` (`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;
