Добавил SQL примеры в проект

This commit is contained in:
Struchkov Mark 2022-09-25 09:30:41 +03:00
parent 41af59a122
commit ebf825b448
3 changed files with 74 additions and 0 deletions

14
sql/cascade-update.sql Normal file
View File

@ -0,0 +1,14 @@
CREATE TABLE status
(
id BIGINT NOT NULL PRIMARY KEY,
title VARCHAR(30) NOT NULL UNIQUE
);
CREATE TABLE post
(
id BIGINT NOT NULL PRIMARY KEY,
title VARCHAR(60),
status VARCHAR(30) NOT NULL
CONSTRAINT fk_post_status_status_title
REFERENCES status(title) ON UPDATE CASCADE
);

View File

@ -0,0 +1,41 @@
CREATE TABLE tutorials
(
id BIGINT NOT NULL PRIMARY KEY,
description VARCHAR(255),
published BOOLEAN,
title VARCHAR(255)
);
CREATE TABLE photos
(
id BIGINT NOT NULL PRIMARY KEY,
description VARCHAR(255),
published BOOLEAN,
title VARCHAR(255)
);
CREATE TABLE comments
(
id BIGINT NOT NULL PRIMARY KEY,
content TEXT
);
CREATE TABLE tutorial_comments
(
tutorial_id BIGINT NOT NULL
CONSTRAINT fk_tutorial_comments_tutorial_id
REFERENCES tutorials,
comment_id BIGINT NOT NULL
CONSTRAINT fk_tutorial_comments_comment_id
REFERENCES comments
);
CREATE TABLE photos_comments
(
photo_id BIGINT NOT NULL
CONSTRAINT fk_photos_comments_photo_id
REFERENCES photos,
comment_id BIGINT NOT NULL
CONSTRAINT fk_photos_comments_comment_id
REFERENCES comments
)

View File

@ -0,0 +1,19 @@
CREATE TABLE tutorials
(
id BIGINT NOT NULL PRIMARY KEY,
description VARCHAR(255),
published BOOLEAN,
title VARCHAR(255)
);
CREATE TABLE comments
(
id BIGINT NOT NULL PRIMARY KEY,
content TEXT,
tutorial_id BIGINT NOT NULL
CONSTRAINT fk_comments_tutorial_id
REFERENCES tutorials
);
CREATE INDEX fk_comments_index ON comments (tutorial_id);