NoSQL: ์ ๋์
๋๋ฆฌ ํํ๋ก ์๊น
์ฅ์ - ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ์ ๋ถ ๋ฃ์ ์ ์๋ค.(๋ฐ์ดํฐ ๊ตฌ์กฐ๋ณํ์ ์ ์ฐํจ)
- ์๋๊ฐ ๋น ๋ฅด๋ค.
1์ฐจ ์ ๊ท
2์ฐจ ์ ๊ท : ๋ชจ๋ ์์ฑ์ ๊ธฐ๋ณธํค์ ์ข ์
one to one:
ํ
์ด๋ธ A์ ๋ก์ฐ์ ํ
์ด๋ธ B์ ๋ก์ฐ๊ฐ ์ ํํ ์ผ๋์ผ ๋งค์นญ์ด ๋๋๊ด๊ณ
one to many:
ํ
์ด๋ธ A์ ๋ก์ฐ๊ฐ ํ
์ด๋ธ B์ ์ฌ๋ฌ ๋ก์ฐ์ ์ฐ๊ฒฐ์ด ๋๋ ๊ด๊ณ
many to many:
ํ
์ด๋ธ A์ ์ฌ๋ฌ ๋ก์ฐ๊ฐ ํ
์ด๋ธ B์ ์ฌ๋ฌ ๋ก์ฐ์ ์ฐ๊ฒฐ์ด ๋๋ ๊ด๊ณ
(๋ฌผ๋ฆฌ์ ์ผ๋ก ํํํ ๋ ์ค๊ฐํ
์ด๋ธ์ด ํ์ํ๋ค.)
1. ์ซ์๋ก ์ ์ฅํ๋ค(๋ฉ๋ชจ๋ฆฌ์ ์ฝ)
2. ์กฐํฉ์ ๋ํ ์ ๋ณด๋ฅผ ์ฐ๊ฒฐํ ์ ์๋ค.
3. id ๊ฐ์ ์ฐธ์กฐํ๊ธฐ๋๋ฌธ์ id์ ์ํ ๋ด์ฉ๋ง ๋ณ๊ฒฝํด์ฃผ๋ฉด ๋ชจ๋ ํ
์ด๋ธ์ ๊ฐ์ ์์ ํ ์ ์๋ค.(ํธํ ๋ฐ์ดํฐ ์ ์ง๋ณด์)
ERD (Entity Relationship Diagram)
๋ฐ์ดํฐ ๊ตฌ์กฐ๊ฐ ์๊ฐํ๋ ๋ํ
์คํ๋ฒ
์ค
1. ์นดํ
๊ณ ๋ฆฌ
-
-
2. ์ ํ
-
-
๊ณต๋ถ.
RENAME TABLE topic TO topic_backup;
"Every table in the database need to have a single theme"
DATA Table ์ ๋ณผ๋ ์ค๋ณต๋๋ ๋ ์ฝ๋๋ ๊ผญ ์ ์ง๋ณด์๋ฅผ ์ํด์ ๋ถ๋ฆฌ๋ฅผ ํด์ผํ๋ค.
Topic
id | title | description | name | city | job_title | job_description |
---|---|---|---|---|---|---|
1 | HTML | HTML is... | Amuse | Seoul | developer | developer is... |
2 | CSS | CSS is... | Goku | Jeju | actor | actor is ... |
3 | DATABASE | DATABASE is... | Ellie | Youtube | developer | developer is ... |
Topic
tid | title | description | author_id |
---|---|---|---|
1 | HTML | HTML is... | 1 |
2 | CSS | CSS is... | 2 |
3 | DATABASE | DATABASE is... | 3 |
4 | Oracle | Oracle is ... | NULL |
author
aid | name | city | profile_id |
---|---|---|---|
1 | Amuse | Seoul | 1 |
2 | Goku | Jeju | 2 |
3 | Ellie | Youtube | 3 |
profile
pid | tittle | job_description |
---|---|---|
1 | developer | developer is ... |
2 | actor | actor is ... |
SELECT * FROM topic LEFT JOIN author ON topic.author_id = author.aid
id | title | description | author_id | aid | name | city | profile_id |
---|---|---|---|---|---|---|---|
1 | HTML | HTML is... | 1 | 1 | Amuse | seoul | 1 |
2 | CSS | CSS is... | 2 | 2 | Goku | Jeju | 2 |
3 | DATABASE | DATABASE is... | 3 | 3 | Ellie | Youtube | 1 |
4 | Oracle | Oracle is ... | NULL | NULL | NULL | NULL | NULL |
SELECT * FROM topic LEFT JOIN author ON topic.author_id = author.aid LEFT JOIN profile ON author.profile_id = profile.pid;
id | title | description | author_id | aid | name | city | profile_id | pid | title | job_description |
---|---|---|---|---|---|---|---|---|---|---|
1 | HTML | HTML is... | 1 | 1 | Amuse | seoul | 1 | 1 | developer | developer is... |
2 | CSS | CSS is... | 2 | 2 | Goku | Jeju | 2 | 2 | actor | actor is ... |
3 | DATABASE | DATABASE is... | 3 | 3 | Ellie | Youtube | 1 | 1 | developer | developer is ... |
4 | Oracle | Oracle is ... | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
SELECT topic.title, topic.description, name, city, profile.title AS job FROM topic LEFT JOIN author ON topic.author_id = author.aid LEFT JOIN profile ON author.profile_id = profile.pid;
title | description | name | city | job |
---|---|---|---|---|
HTML | HTML is... | Amuse | seoul | developer |
CSS | CSS is... | Goku | Jeju | actor |
DATABASE | DATABASE is... | Ellie | Youtube | developer |
SELECT * FROM topic INNER JOIN author ON topic.author_id = author.aid;
SELECT * FROM topic FULL OUTER JOIN author ON topic.author_id = author.aid;
Reference
https://sql-joins.leopard.in.ua/
https://opentutorials.org/course/3884/25180