DROP DATABASE IF EXISTS filmy;
DROP USER IF EXISTS filmoznawca;

CREATE DATABASE filmy CHARACTER SET = 'utf8' COLLATE = 'utf8_polish_ci';
USE filmy;

CREATE TABLE filmy(
id_film INT(6)  PRIMARY KEY,
tytul VARCHAR(128) NOT NULL,
data_premiery DATE NOT NULL,
srednia_ocena float
);

CREATE TABLE aktorzy(
id_aktor INT PRIMARY KEY,
imie VARCHAR(128) NOT NULL,
nazwisko  VARCHAR(128) NOT NULL
);

CREATE TABLE aktorzy_w_filmie(
id INT PRIMARY KEY,
id_film int NOT NULL,
id_aktor int NOT NULL,
ocena float,
FOREIGN KEY (id_film) REFERENCES filmy(id_film) ON DELETE CASCADE,
FOREIGN KEY (id_aktor) REFERENCES aktorzy(id_aktor) ON DELETE CASCADE
);
