-- MySQL Script generated by MySQL Workbench
-- Mon Apr  6 15:11:43 2020
-- 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';

-- -----------------------------------------------------
-- Schema es1_esami
-- -----------------------------------------------------

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

-- -----------------------------------------------------
-- Table `es1_esami`.`studente`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `es1_esami`.`studente` (
  `matricola` INT NOT NULL,
  `cognome` VARCHAR(45) NOT NULL,
  `nome` VARCHAR(45) NOT NULL,
  `citta_nascita` VARCHAR(45) NOT NULL,
  `citta_residenza` VARCHAR(45) NOT NULL,
  `corso_laurea` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`matricola`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `es1_esami`.`corso`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `es1_esami`.`corso` (
  `codice` INT NOT NULL,
  `nome` VARCHAR(45) NOT NULL,
  `ore_lezione` INT NOT NULL,
  `ore_esercitazione` INT NULL,
  `crediti_lezione` INT NOT NULL,
  `crediti_esercitazione` INT NULL,
  `docente` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`codice`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `es1_esami`.`esame`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `es1_esami`.`esame` (
  `matricola_studente` INT NOT NULL,
  `codice_corso` INT NOT NULL,
  `data` DATETIME NOT NULL,
  `voto` INT NOT NULL,
  PRIMARY KEY (`matricola_studente`, `codice_corso`),
  INDEX `Matricola_idx` (`matricola_studente` ASC) VISIBLE,
  INDEX `Corso_idx` (`codice_corso` ASC) VISIBLE,
  CONSTRAINT `Matricola_key`
    FOREIGN KEY (`matricola_studente`)
    REFERENCES `es1_esami`.`studente` (`matricola`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `Corso_key`
    FOREIGN KEY (`codice_corso`)
    REFERENCES `es1_esami`.`corso` (`codice`)
    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;
