CREATE SCHEMA IF NOT EXISTS offerta_formativa; CREATE TABLE IF NOT EXISTS offerta_formativa.docente ( matricola INT NOT NULL, cognome VARCHAR(45) NOT NULL, nome VARCHAR(45) NOT NULL, citta_residenza VARCHAR(45) NOT NULL, ruolo ENUM('professore ordinario', 'professore associato', 'ricercatore') NOT NULL, PRIMARY KEY (matricola)) ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS offerta_formativa.corso_laurea ( codice INT NOT NULL, nome VARCHAR(45) NOT NULL, tipologia ENUM('triennale', 'magistrale') NOT NULL, presidente INT NOT NULL, PRIMARY KEY (codice), CONSTRAINT fk_presidente FOREIGN KEY (presidente) REFERENCES offerta_formativa.docente (matricola) ON UPDATE CASCADE ON DELETE RESTRICT) ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS offerta_formativa.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 INT NOT NULL, PRIMARY KEY (codice), CONSTRAINT fk_docente FOREIGN KEY (docente) REFERENCES offerta_formativa.docente (matricola) ON UPDATE CASCADE ON DELETE RESTRICT) ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS offerta_formativa.corso_di_laurea_corsi ( codice_corso_laurea INT NOT NULL, codice_corso INT NOT NULL, PRIMARY KEY (codice_corso, codice_corso_laurea), CONSTRAINT fk_corso_laurea FOREIGN KEY (codice_corso_laurea) REFERENCES offerta_formativa.corso_laurea (codice) ON UPDATE CASCADE ON DELETE RESTRICT, CONSTRAINT fk_corso FOREIGN KEY (codice_corso) REFERENCES offerta_formativa.corso (codice) ON UPDATE CASCADE ON DELETE RESTRICT) ENGINE = InnoDB;