Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
1.3 kB
0
Indexable
Never
CREATE TABLE IF NOT EXISTS ganre (
    id   INT         GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name varchar(30) UNIQUE NOT NULL
);

CREATE TABLE IF NOT EXISTS rating (
    id   INT         GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name varchar(10) UNIQUE
);

CREATE TABLE IF NOT EXISTS film (
    id           INT          GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name         varchar(30)  NOT NULL,
    description  varchar(200) NOT NULL,
    release_date DATE         NOT NULL,
    duration     INT          NOT NULL,
    rating_id    INT          NOT NULL,
    FOREIGN KEY (rating_id)  REFERENCES rating (id)
);

CREATE TABLE IF NOT EXISTS ganre_to_film (
    film_id  INT  NOT NULL,
    ganre_id INT  NOT NULL,
    FOREIGN KEY (ganre_id)  REFERENCES ganre (id),
    FOREIGN KEY (film_id)  REFERENCES film (id)
);

CREATE TABLE IF NOT EXISTS users (
    id        INT          GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name      varchar(30)  NOT NULL,
    email     varchar(200) NOT NULL,
    login     varchar(50)  NOT NULL,
    birthday  DATE         NOT NULL
);

CREATE TABLE IF NOT EXISTS likes (
    film_id INT  NOT NULL,
    user_id INT  NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users (id),
    FOREIGN KEY (film_id) REFERENCES film (id)
);
Leave a Comment