DROP TABLE aime;
DROP TABLE jouer;
DROP TABLE vu;
DROP TABLE cinema;
DROP TABLE film;
DROP TABLE individu;

CREATE TABLE individu
	(
	noSpect serial NOT NULL
		CONSTRAINT individu_pk PRIMARY KEY,
	nomSpect VARCHAR(32)
	);

CREATE TABLE film
	(
	noFilm serial NOT NULL
		CONSTRAINT film_pk PRIMARY KEY,
	titre VARCHAR(32),
	noRealisateur int,
		CONSTRAINT realisateur_fk FOREIGN KEY (noRealisateur) REFERENCES individu (noSpect),
	noProducteur int,
		CONSTRAINT producteur_fk FOREIGN KEY (noProducteur) REFERENCES individu (noSpect)
	);
	
CREATE TABLE cinema
	(
	noFilm int NOT NULL,
	noSalle int NOT NULL,
	heure int NOT NULL,
		CONSTRAINT cinema_pk PRIMARY KEY (noFilm,noSalle,heure)
	);
	
CREATE TABLE vu
	(
	noFilm int NOT NULL,
	noSpect int NOT NULL,
		CONSTRAINT vu_pk PRIMARY KEY (noFilm,noSpect),
			CONSTRAINT filmVu_fk FOREIGN KEY (noFilm) REFERENCES film (noFilm),
			CONSTRAINT spectVu_fk FOREIGN KEY (noSpect) REFERENCES individu (noSpect)
	);
	
CREATE TABLE jouer
	(
	noFilm int NOT NULL,
	noActeur int NOT NULL,
		CONSTRAINT jouer_pk PRIMARY KEY (noFilm,noActeur),
			CONSTRAINT filmJouer_fk FOREIGN KEY (noFilm) REFERENCES film (noFilm),
			CONSTRAINT spectJouer_fk FOREIGN KEY (noActeur) REFERENCES individu (noSpect)
	);
	
CREATE TABLE aime
	(
	noFilm int NOT NULL,
	noSpect int NOT NULL,
		CONSTRAINT aime_pk PRIMARY KEY (noFilm,noSpect),
			CONSTRAINT filmAime_fk FOREIGN KEY (noFilm) REFERENCES film (noFilm),
			CONSTRAINT spectAime_fk FOREIGN KEY (noSpect) REFERENCES individu (noSpect)
	);
