mirror of
https://github.com/Example-uPagge/spring-boot-one-to-many.git
synced 2024-06-14 11:22:31 +03:00
Добавил SQL примеры в проект
This commit is contained in:
parent
41af59a122
commit
ebf825b448
14
sql/cascade-update.sql
Normal file
14
sql/cascade-update.sql
Normal 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
|
||||
);
|
41
sql/create-many-to-one.sql
Normal file
41
sql/create-many-to-one.sql
Normal 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
|
||||
)
|
19
sql/create-one-to-many.sql
Normal file
19
sql/create-one-to-many.sql
Normal 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);
|
Loading…
Reference in New Issue
Block a user