drop database IF EXISTS testateGiornalistiche; create database testateGiornalistiche; use testateGiornalistiche; drop table IF EXISTS redazioni; create table IF NOT EXISTS redazioni( idRedazione char(4) primary key, nomeComitato char(10), citta char(8), indirizzoWeb char(20)); drop table IF EXISTS testate; create table IF NOT EXISTS testate( idTestata char(4) primary key, nome char(20), redazione char(4), foreign key(redazione) references redazioni(idRedazione)); drop table IF EXISTS redattori; create table IF NOT EXISTS redattori( idRedattori char(3) primary key, cognome char(10), nome char(8), via char(15), provincia char(2), CAP char(5), email text); drop table IF EXISTS categorie; create table IF NOT EXISTS categorie( nomeCategoria char(10) primary key, categoriaPadre char(10), foreign key(categoriaPadre) references categorie(nomeCategoria)); drop table IF EXISTS inserzioni; create table IF NOT EXISTS inserzioni( codice char(6) primary key, testo char(50), categoria char(10), foreign key(categoria) references categorie(nomeCategoria)); drop table IF EXISTS aziende; create table IF NOT EXISTS aziende( idAzienda char(6) primary key, nomeAzienda char(40), referente char(40), telefono char(11)); drop table IF EXISTS privati; create table IF NOT EXISTS privati( idPrivato char(3) primary key, cognome char(10), nome char(8), via char(15), citta char(15), provincia char(2), CAP char(5), email char(20)); drop table IF EXISTS inspriv; create table IF NOT EXISTS inspriv( idPrivato char(6) NOT NULL, idInserzione char(6) NOT NULL, PRIMARY KEY(idPrivato, idInserzione), FOREIGN KEY(idPrivato) references privati(idPrivato), FOREIGN KEY(idInserzione) references inserzioni(codice)); drop table IF EXISTS insaz; create table IF NOT EXISTS insaz( idAzienda char(6) NOT NULL, idInserzione char(6) NOT NULL, FOREIGN KEY(idAzienda) references aziende(idAzienda), FOREIGN KEY(idInserzione) references inserzioni(codice), PRIMARY KEY(idAzienda, idInserzione)); drop table IF EXISTS instest; create table IF NOT EXISTS instest( idInserzione char(6) NOT NULL, idTestata char(4) NOT NULL, FOREIGN KEY(idInserzione) references inserzioni(codice), FOREIGN KEY(idTestata) references testate(idTestate), PRIMARY KEY(idInserzione, idTestata)); drop table IF EXISTS redazRedat; create table IF NOT EXISTS redazRedat( idRedazione char(4) NOT NULL, idRedattori char(3) NOT NULL, FOREIGN KEY(idRedazione) references redazioni(idRedazione), FOREIGN KEY(idRedattori) references redattori(idRedattori), PRIMARY KEY(idRedazione, idRedattori));