์ถ์ฒ - ์ฌ์ด์ฝ๋ Youtube
โ ์ํ์์์ Relation?
- ์ฌ๋ฌ ๊ฐ์ set์ ์์๋ค์ ๋ชจ๋ ๊ฐ๋ฅํ ์กฐํฉ์ผ๋ก ์ด๋ฃจ์ด์ง ์๋ก์ด set์ Cartesian product๋ผ๊ณ ํ๋ค.
- ์ด cartesian product์ ๋ถ๋ถ์งํฉ์ ๋๋ ํํ๋ค์ ์งํฉ์ relation์ด๋ผ๊ณ ํ๋ค.
โ ๊ด๊ณํ ๋ฐ์ดํฐ ๋ชจ๋ธ์์์ relation?
- ์ฌ๋ฌ ๊ฐ์ ๋๋ฉ์ธ(set)์ ๊ฐ๋ค๋ก ๋ง๋ค ์ ์๋ ์กฐํฉ๋ค์ ์งํฉ
โ ๊ด๊ณํ ๋ฐ์ดํฐ ๋ชจ๋ธ ์ฃผ์ ๊ฐ๋ (์ฉ์ด ์ ๋ฆฌ)
- domain : Atomicํ ๊ฐ๋ค์ ์งํฉ
- attribute : domain์ด relation์์ ๋งก์ ์ญํ ์ด๋ฆ
- tuple : ๊ฐ attribute์ ๊ฐ์ผ๋ก ์ด๋ฃจ์ด์ง ๋ฆฌ์คํธ (์ผ๋ถ ๊ฐ์ NULL์ผ ์ ์๋ค.)
- relation : ํํ๋ค์ ์งํฉ
- relation name : relation์ ์ด๋ฆ
โ ์์ - Student relation
๐ฅ Student domain ์ ์ํ๊ธฐ
- student_ids : 7์๋ฆฌ integer
- human_names : ๋ฌธ์์ด
- university_grades : {1,2,3,4} ์ค ํ๋
- major_names : ์ ๊ณต์ด๋ฆ ์งํฉ
- phone_numbers : ์ ํ๋ฒํธ
๐ฅ Relation ๋ง๋ค๊ธฐ
- Relation์ ๋ง๋๋ ค๋ค๋ณด๋, phone_numbers ๋๋ฉ์ธ์ด 2๊ฐ ํ์ํ ๊ฒ ๊ฐ๋ค. (1. ๋ณธ์ธ๋ฒํธ ์ ์ฅ ๋ชฉ์ , 2. ๋น์์ฐ๋ฝ๋ง ์ ์ฅ ๋ชฉ์ )
--> ํ๋์ ๋ฆด๋ ์ด์ ์์์ ๊ฐ์ ๋๋ฉ์ธ์ด ๋ค๋ฅธ ๋ชฉ์ (์ญํ )์ ๊ฐ์ง๊ณ 2๋ฒ ์ฌ์ฉ๋๋ค
--> ์ด ๋๋ฉ์ธ๋ค์ ์ญํ ์ ์ ์ํด์ฃผ๊ธฐ ์ํด์, ๊ฐ ๋๋ฉ์ธ์ ์์ฑ(attribute)์ ๋ถ์ฌํ๋ค.
- ๊ทธ๋ฆผ์์ ์ฒซ ๋ฒ์งธ ํ์ domain ์ด๋ฆ, ๋ ๋ฒ์งธ ํ์ attribute ์ด๋ฆ
- ๊ฐ ๋๋ฉ์ธ์ ๊ฐ๋ค๋ก ์ด๋ฃจ์ด์ง ํํ๋ก Relation์ ๋ง๋ค ์ ์๊ณ , ์ด ๋ฆด๋ ์ด์ ์ ๋ณด๊ธฐ ์ข๊ฒ ํ ์ด๋ธ ํํ๋ก ๋ํ๋ผ ์ ์๋ค.
- ๋ฆด๋ ์ด์ (ํ ์ด๋ธ)์ ๊ฐ ํ์ ํํ, ๊ฐ ์ด์ attribute ์ด๋ค.
โ Relation schema
- Relation์ ๊ตฌ์กฐ๋ฅผ ๋ํ๋ธ๋ค.
- Relation์ด๋ฆ(attribute ๋ฆฌ์คํธ) ๋ก ํ๊ธฐ๋๋ค.
- ์์: STUDENT(id, name, grade, major, phone_num, emer_phone_num)
- Relation schema๋ attribute๋ฟ๋ง์๋๋ผ attributes์ ๊ด๋ จ๋ constraints๋ ํฌํจํ๋ค.
โ Degree of a relation
- Relation schema์์ attributes์ ๊ฐ์
- ์์: ์ ๋ฆด๋ ์ด์ ์ degree๋ 6
โญ๏ธ Relational Database(๊ด๊ณํ ๋ฐ์ดํฐ๋ฒ ์ด์ค)๋?
- Relational data model์ ๊ธฐ๋ฐํ์ฌ ๊ตฌ์กฐํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค
- Relational database๋ ์ฌ๋ฌ ๊ฐ์ ๋ฆด๋ ์ด์ ์ผ๋ก ๊ตฌ์ฑ๋๋ค.
๐ฅ Relational database schema?
- Relation schema๋ค์ ์งํฉ + integrity constraints set
โ Relation์ ํน์ง
- ์ค๋ณต๋ ํํ์ ๊ฐ์ง ์ ์๋ค. (๋ฆด๋ ์ด์ ์ ์ ์๋ถํฐ ํํ๋ค์ "์งํฉ"์ด๊ธฐ ๋๋ฌธ)
- ๋ฆด๋ ์ด์ ์์ ํํ์ ์์์ attribute์ ์์๋ ์ค์ํ์ง ์๋ค. (์งํฉ์ด๋๊น!)
- ๋ฆด๋ ์ด์ ์ ํํ์ uniqueํ๊ฒ ์๋ณํ๊ธฐ ์ํด, attribute์ ๋ถ๋ถ์งํฉ์ key๋ก ์ค์ ํ๋ค.
- ํ๋์ ๋ฆด๋ ์ด์ ์์ attribute์ ์ด๋ฆ์ ์ค๋ณต๋ ์ ์๊ณ , atomicํด์ผํ๋ค.
- Attribute๊ฐ atomicํด์ผํ๋ค => ํ๋์ attribute๊ฐ ๋๋ ์ง ์ ์๋ ์ฌ๋ฌ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ composite(or multivalued) attribute๊ฐ ๋๋ฉด ์ ๋๋ค
โ Null์ ์ธ์ ์ฌ์ฉ๋๋๊ฐ
- ๊ฐ์ด ์กด์ฌํ์ง ์์ ๋
- ๊ฐ์ด ์กด์ฌํ์ง๋ง, ์์ง ๊ทธ ๊ฐ์ด ๋ฌด์์ธ์ง ๋ชจ๋ฅผ ๋
- ํด๋น ์ฌํญ๊ณผ ๊ด๋ จ ์์ ๋
- Null์ ์ค์์ ์ธ ์๋ฏธ๋ฅผ ๊ฐ์ง ์ ์๊ธฐ ๋๋ฌธ์ ๋๋๋ก ์ฌ์ฉํ์ง ์๋ ๊ฒ์ด ์ข๋ค .
โ KEY
๐ Super Key (์ํผํค)
- ๋ฆด๋ ์ด์ ์์ ํํ์ uniqueํ๊ฒ ์๋ณํ ์ ์๋ attribute์ ๋ถ๋ถ์งํฉ
๐ Candidate Key (ํ๋ณดํค)
- ์ด๋ ํ attribute๋ผ๋ ์ ๊ฑฐํ๋ฉด super key๊ฐ ์๋๊ฒ ๋๋ super key
- key ๋๋ minimal superkey๋ผ๊ณ ๋ถ๋ฅด๊ธฐ๋ ํ๋ค.
๐ Primary Key (๊ธฐ๋ณธํค)
- ๋ฆด๋ ์ด์ ์์ ํํ์ uniqueํ๊ฒ ์๋ณํ๊ธฐ ์ํด ์ ํ๋ candidate key
- ๋ณดํต attribute ์๊ฐ ๊ฐ์ฅ ์ ์ ํค๋ฅผ primary key๋ก ์ ํํ๋ค. (ํธํ๋๊น!)
๐ Unique Key ๋๋ Alternate Key (๋์ฒดํค)
- Primary key๊ฐ ์๋ candidate key
๐ Foreign Key (์ธ๋ํค)
- ๋ค๋ฅธ ๋ฆด๋ ์ด์ ์ Primary Key๋ฅผ ์ฐธ์กฐํ๋ attribute์ ๋ถ๋ถ์งํฉ
โ Constraints
- Relational database์ ๋ฆด๋ ์ด์ ๋ค์ด ์ธ์ ๋ ํญ์ ์ง์ผ์ค์ผ ํ๋ ์ ์ฝ์ฌํญ
๐ฅ Implicit Constraints
- Relation data model ์์ฒด๊ฐ ๊ฐ์ง๋ constraints
- ์์ ) Relation์ ์ค๋ณต๋๋ ํํ์ ๊ฐ์ง ์ ์๋ค, ๋ฆด๋ ์ด์ ๋ด์์๋ ๊ฐ์ ์ด๋ฆ์ attribute๋ฅผ ๊ฐ์ง ์ ์๋ค
๐ฅ Schema-based Constraints
- Explicit constraints๋ผ๊ณ ๋ ํ๋ค
- ์ฃผ๋ก DDL์ ํตํด ์คํค๋ง์ ์ง์ ๋ช ์ํ ์ ์๋ constraints
- ์ข ๋ฅ
- Domain constraints : Attribute์ value๋ ํด๋น attribute์ ๋๋ฉ์ธ์ ์ํ value์ฌ์ผ ํ๋ค.
- Key constraints : ์๋ก ๋ค๋ฅธ ํํ๋ค์ ๊ฐ์ value์ key๋ฅผ ๊ฐ์ง ์ ์๋ค.
- Null value constraints : Attribute๊ฐ NOT NULL๋ก ๋ช ์๋์๋ค๋ฉด, value๋ก null์ ๊ฐ์ง ์ ์๋ค.
- Entity integrity constraints : Primary key๋ value๋ก null์ ๊ฐ์ง ์ ์๋ค.
- Referential integrity constraints : FK์ PK์ ๋๋ฉ์ธ์ด ๊ฐ์์ผ ํ๊ณ , FK๋ value๋ก PK์ ์๋ value๋ฅผ ๊ฐ์ง ์ ์๋ค.
'๊ฐ์ธ ๊ณต๋ถ > DB' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
DBMS์์ ๋ฐ์ดํฐ ์ ์ฅ ๋ฐฉ์ (Heap, ISAM, B+ Tree) (1) | 2024.11.08 |
---|---|
๊ด๊ณ ๋ชจ๋ธ์ ๋ฆด๋ ์ด์ ๊ณผ ๋ฌด๊ฒฐ์ฑ ์ ์ฝ์กฐ๊ฑด (1) | 2024.11.07 |
DBMS๋ฅผ ์ฌ์ฉํ๋ ์ด์ ์ DBMS ์คํค๋ง (0) | 2024.11.07 |
๊ด๊ณ๋์์ (1) | 2023.12.27 |
[๊ฐ์ ์ ๋ฆฌ] ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ฐ๋ก (0) | 2023.08.28 |