CREATE TABLE directors (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nev VARCHAR(255)
);

CREATE TABLE genres (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nev VARCHAR(100) UNIQUE NOT NULL
);

CREATE TABLE films (
  id INT AUTO_INCREMENT PRIMARY KEY,
  cim VARCHAR(255) NOT NULL,
  eredeti_cim VARCHAR(255),
  év SMALLINT,
  hossz SMALLINT,
  korhatar VARCHAR(2) NOT NULL,
  leiras TEXT,
  rendező_id INT NOT NULL,
  mufaj_id INT NOT NULL,
  nyelv VARCHAR(50),
  megjelenes DATE,
  imdb_id VARCHAR(50),
  CHECK (korhatar in ("NK","6","12","16","18")),
  FOREIGN KEY (rendező_id) REFERENCES directors(id),
  FOREIGN KEY (mufaj_id) REFERENCES genres(id)
  );

CREATE TABLE actors (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nev VARCHAR(255),
  szul_datum DATE,
  orszag VARCHAR(100)
);

CREATE TABLE film_actor (
  id INT AUTO_INCREMENT PRIMARY KEY,
  film_id INT NOT NULL,
  actor_id INT NOT NULL,
  karakter_nev VARCHAR(255),
  UNIQUE(film_id, actor_id, karakter_nev),
  FOREIGN KEY (film_id) REFERENCES films(id),
  FOREIGN KEY (actor_id) REFERENCES actors(id)
);
