From ebf825b448a11f047b529bdcc3af0aa71c400d74 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sun, 25 Sep 2022 09:30:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20SQ?= =?UTF-8?q?L=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D1=8B=20=D0=B2=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/cascade-update.sql | 14 +++++++++++++ sql/create-many-to-one.sql | 41 ++++++++++++++++++++++++++++++++++++++ sql/create-one-to-many.sql | 19 ++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 sql/cascade-update.sql create mode 100644 sql/create-many-to-one.sql create mode 100644 sql/create-one-to-many.sql diff --git a/sql/cascade-update.sql b/sql/cascade-update.sql new file mode 100644 index 0000000..6f14dbf --- /dev/null +++ b/sql/cascade-update.sql @@ -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 +); \ No newline at end of file diff --git a/sql/create-many-to-one.sql b/sql/create-many-to-one.sql new file mode 100644 index 0000000..d20e1f7 --- /dev/null +++ b/sql/create-many-to-one.sql @@ -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 +) \ No newline at end of file diff --git a/sql/create-one-to-many.sql b/sql/create-one-to-many.sql new file mode 100644 index 0000000..d4dee2a --- /dev/null +++ b/sql/create-one-to-many.sql @@ -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); \ No newline at end of file