Normalization์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ค๊ณ์์ ์ค๋ณต์ ์ต์ํํ๊ณ ๋ฐ์ดํฐ ์ผ๊ด์ฑ์ ์ ์งํ๊ธฐ ์ํ ํ๋ก์ธ์ค์ ๋๋ค. ์ด๋ ๋ฐ์ดํฐ๋ฅผ ์ ์ ํ ํ ์ด๋ธ์ ๋ถ์ฐ์์ผ ์ค๋ณต์ ๋ฐฉ์งํ๊ณ , ๋ฐ์ดํฐ ๊ฐ์ ์ข ์์ฑ์ ๊ด๋ฆฌํ์ฌ ๋ฐ์ดํฐ์ ์ผ๊ด์ฑ๊ณผ ํจ์จ์ฑ์ ํฅ์์ํต๋๋ค.

- FD์ KEY๋ง์ผ๋ก ์ ์๋๋ Normal Forms
- 3NF๊น์ง ๋๋ฌํ๋ฉด ์ ๊ทํ๋์๋ค๊ณ ๋งํ ์ ์๋ค
- ๋ณดํต ์ค๋ฌด์์๋ 3NF ํน์ BCNF๊น์ง๋ง ์งํ
์ ๊ทํ์ ๋ค์ด๊ฐ๊ธฐ ์ ์ ์์๋ณผ ์ฌ๋ฌ๊ฐ์ง Key
- Super Key (์ํผํค): ์ํผํค๋ ๋ฆด๋ ์ด์ ์์ ํํ๋ค์ ์ ์ผํ๊ฒ ์๋ณํ ์ ์๋ ์์ฑ(๋๋ ์์ฑ์ ์งํฉ)์ ์กฐํฉ
- Candidate Key (ํ๋ณด ํค): ํ๋ณด ํค๋ ์ํผ ํค์ด๋ฉด์๋ ๋ ๊ฐ์ attributes๊ฐ ์ํผํค๋ก ํ์ฝํ ๋ (ํ๋๊ฐ ์์ผ๋ฉด ์ ๋จ)
- Primary Key (๊ธฐ๋ณธ ํค): ๊ธฐ๋ณธ ํค๋ ํ๋ณด ํค ์ค์์ ์ ํ๋ ์ฃผ ํค๋ก, ๊ฐ ํํ์ ์ ์ผํ๊ฒ ์๋ณํ๋ ์ฃผ์ ์์ฑ
- Prime Attribute (ํ๋ผ์ ์์ฑ): ์ํผํค, ํ๋ณดํค, ๊ธฐ๋ณธํค ์ด๋๋ผ๋ 'ํค'๋ผ๋ ์์ญ์ ์ํด ์๋ ์์ฑ
- Non-Prime Attribute (๋นํ๋ผ์ ์์ฑ): ๋นํ๋ผ์ ์์ฑ์ ํ๋ณด ํค์ ๊ตฌ์ฑ์ ํฌํจ๋์ง ์์ ๋๋จธ์ง ์์ฑ
1NF (First Normal Form - ์ 1 ์ ๊ทํ)
ํ ์ด๋ธ์ ๊ฐ ์์ฑ์ ์์๊ฐ(Atomic Value)์ ๊ฐ์ ธ์ผ ํฉ๋๋ค. ์ฆ, ๊ฐ ์์ฑ์๋ ํ๋์ ๊ฐ๋ง ์์ด์ผ ํ๋ฉฐ, ๋ค์ค ๊ฐ์ด๋ ๋ชฉ๋ก์ ํฌํจํ์ง ์์์ผ ํฉ๋๋ค.


2NF (Second Normal Form - ์ 2 ์ ๊ทํ)
ํ ์ด๋ธ์ด 1NF์ด๋ฉด์, ๋ชจ๋ Non-prime attribute๋ ๋ชจ๋ key์ fully functionally dependent ํด์ผ ํ๋ค.

- ์ํผํค์ธ account_id (X) ์์ฑ์ด non-prime attributes๋ค์ ๊ฒฐ์ ์ํค์ง ๋ชปํ๊ณ ์์ต๋๋ค.
- ํ๋ณดํค์ธ {bank_name, account_name} ์์ฑ์ด non-prime attributes๋ค์ ๊ฒฐ์ ์ํค์ง ๋ชปํ๊ณ ์์ต๋๋ค.


3NF (Third Normal Form - ์ 3 ์ ๊ทํ)
ํ ์ด๋ธ์ด 2NF์ด๋ฉด์, non-prime attribute๋ ์ด๋ค key์๋ transitively dependentํ๋ฉด ์ ๋๋ค. (non-prime attributes ์ฌ์ด์๋ FD๊ฐ ์์ผ๋ฉด ์ ๋๋ค)
Transitive FD
X -> Y & Y -> Z ์ผ ๋, X -> Z (unless either Y or Z is not subset๋ถ๋ถ์ง of any key)

- {bank_name, account_num} (X) -> empl_id (Y), empl_id (Y) -> empl_name (Z) : transitively dependent ์ผ์ด๋๊ณ ์๋ค!!
- (์์ ์กฐ๊ฑด์ ์ข ๋ ์ฝ๊ฒ) non-prime attribute์ธ empl_id๊ฐ empl_name์ FDํ๊ณ ์๋ค!!


BCNF (Boyce-Codd Normal Form)
ํ ์ด๋ธ์ด 3NF์ด๋ฉด์, ๋ชจ๋ ์ ํจํ non-trivial FD X -> Y๋ X๊ฐ super key์ฌ์ผ ํ๋ค.

- Class(X)์ ์ํ ์ด๋ฆ(Y)์ด FD ๊ด๊ณ์ ์๋ค. BCNF์ ๋ฐ๋ฅด๋ฉด X๋ ์ํผํค์ฌ์ผ๋ง ํ๋ค. ๊ทผ๋ฐ ์๋๋ค!!


์ญ์ ๊ทํ(Denormalization)
๋๋ก๋ ์ฑ๋ฅ ํฅ์์ด๋ ํน์ ์ฟผ๋ฆฌ์ ์ฒ๋ฆฌ ์๋๋ฅผ ๊ฐ์ ํ๊ธฐ ์ํด ์ ๊ทํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ญ์ผ๋ก ๋ณํํ๋ ๊ณผ์ ์ด ํ์ํ ์ ์์ต๋๋ค. ์ด๊ฒ์ด ๋ฐ๋ก ์ญ์ ๊ทํ(Denormalization)์ ๋๋ค.
- ์ฑ๋ฅ ํฅ์: ์ ๊ทํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ ์ฌ๋ฌ ํ ์ด๋ธ์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ฐ์์ผ ์ ์ฅํ๊ธฐ ๋๋ฌธ์ ๋ฐ์ดํฐ๋ฅผ ๊ฒ์ํ๊ฑฐ๋ ์กฐ์ธํ ๋ ์กฐ๊ธ ๋ ๋ง์ ์๊ฐ๊ณผ ์์์ด ์์
- ๊ฐ๊ฒฐ์ฑ๊ณผ ๊ฐ๋ ์ฑ: ์ ๊ทํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ค๊ณ๋ ์ฌ๋ฌ ํ ์ด๋ธ ๊ฐ์ ๊ด๊ณ๋ฅผ ์ ์งํ๊ธฐ ์ํด ๋ง์ ์กฐ์ธ์ด ํ์
- ํน์ ํ ์ฟผ๋ฆฌ ์ต์ ํ: ํน์ ํ ์ ํ์ ์ฟผ๋ฆฌ์ ๋ํ ์๋ต ์๊ฐ์ ์ต์ ํํ๊ธฐ ์ํด ์ญ์ ๊ทํ๋ฅผ ์ํ
- ๋ณต์ ๋ฐ ์บ์ฑ ํ์ฉ: ์ญ์ ๊ทํ๋ ๋ฐ์ดํฐ์ ์ค๋ณต์ ํตํด ๋ฐ์ดํฐ๋ฅผ ๋ฏธ๋ฆฌ ๊ณ์ฐํ์ฌ ๋ณต์ ํ๊ฑฐ๋ ์บ์ฑํ์ฌ ์ฑ๋ฅ์ ํฅ์
๊ทธ๋ฌ๋ ์ญ์ ๊ทํ๋ฅผ ์ ์ฉํ ๋ ์ฃผ์ํด์ผ ํ ์ ๋ ์์ต๋๋ค. ์ค๋ณต๋ ๋ฐ์ดํฐ์ ์ผ๊ด์ฑ์ ์ ์งํ๊ธฐ ์ํด ์ ๋ฐ์ดํธ ์ฐ์ฐ์ด ํ์ํ๋ฉฐ, ์ด๋ก ์ธํด ๋ฐ์ดํฐ์ ๋ฌด๊ฒฐ์ฑ์ด๋ ์ผ๊ด์ฑ์ด ์ ํด๋ ์ ์์ต๋๋ค. ๋ํ, ์ญ์ ๊ทํ๋ ์ผ๋ฐ์ ์ผ๋ก ์ฐ๊ธฐ ์์ ์ด ๋ง์ ํ๊ฒฝ์์๋ ๊ถ์ฅ๋์ง ์์ ์ ์์ต๋๋ค. ์ญ์ ๊ทํ๋ฅผ ๊ณ ๋ คํ ๋๋ ์์คํ ์ ์๊ตฌ ์ฌํญ๊ณผ ์ฑ๋ฅ ํน์ฑ์ ๊ณ ๋ คํ์ฌ ์ ์คํ๊ฒ ํ๋จํด์ผ ํฉ๋๋ค.
Normalization
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity by decomposing tables into smaller, related tables.
Denormalization
Denormalization is the reverse process of normalization, involving the reintroduction of redundancy to improve query performance, simplify data retrieval, or meet specific performance requirements in a database.
'Computer Science > Database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
25 NoSQL (0) | 2024.01.18 |
---|---|
21 Index (0) | 2024.01.17 |
12 Trigger (0) | 2024.01.13 |
9 ORDER BY, GROUP BY (feat. HAVING) (0) | 2024.01.12 |
8 JOIN (0) | 2024.01.12 |
๋๊ธ