Relational Model ์ˆ˜์ค€์—์„œ Referential Integrity์™€ Foreign Key Constraint๋ฅผ ์„ค๋ช…ํ•˜๊ณ  ์ฐจ์ด๋ฅผ ๋ช…ํ™•ํžˆ ํ•˜๋Š” ๊ด€์ ์€ RDBMS์˜ ๊ตฌํ˜„์„ ๋ฐฐ์ œํ•˜๊ณ  ๊ด€๊ณ„ ๋Œ€์ˆ˜๋‚˜ ๊ด€๊ณ„ ์Šคํ‚ค๋งˆ ์„ค๊ณ„ ์ˆ˜์ค€์—์„œ ์ ‘๊ทผํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.


1. Referential Integrity (์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ)


2. Foreign Key Constraint (์™ธ๋ž˜ ํ‚ค ์ œ์•ฝ ์กฐ๊ฑด)


์ฐจ์ด์ 

ํŠน์ง• Referential Integrity Foreign Key Constraint
๊ฐœ๋…์  ์ˆ˜์ค€ ๊ด€๊ณ„ ๋ชจ๋ธ์—์„œ ๋ฐ์ดํ„ฐ ๊ฐ„ ๋…ผ๋ฆฌ์  ๊ด€๊ณ„๋ฅผ ์ •์˜ํ•˜๋Š” ์›์น™ ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์Šคํ‚ค๋งˆ ์ˆ˜์ค€์—์„œ์˜ ํ˜•์‹์  ์„ ์–ธ
์ดˆ์  ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•œ ์ด๋ก ์  ์›์น™ ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์„ ๊ตฌ์ฒด์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๊ด€๊ณ„ ์Šคํ‚ค๋งˆ์— ํฌํ•จ๋˜๋Š” ์ œ์•ฝ ์กฐ๊ฑด
๊ด€๊ณ„ ์Šคํ‚ค๋งˆ ๊ฐ„ ์ •์˜ ๊ด€๊ณ„ ์Šคํ‚ค๋งˆ R_1์™€ R_2 ๊ฐ„ ์ฐธ์กฐ ๊ด€๊ณ„๋ฅผ ๊ฐœ๋…์ ์œผ๋กœ ์„ค๋ช… ๊ด€๊ณ„ ์Šคํ‚ค๋งˆ R_1์˜ ์†์„ฑ์ด R_2์˜ ๊ธฐ๋ณธ ํ‚ค๋ฅผ ์ฐธ์กฐํ•œ๋‹ค๊ณ  ๋ช…์‹œ์ ์œผ๋กœ ์„ ์–ธ
์ ์šฉ ๋ฐฉ์‹ ๋…ผ๋ฆฌ์  ์„ค๊ณ„ ๋‹จ๊ณ„์—์„œ ๊ณ ๋ ค๋˜๋Š” ์ถ”์ƒ์  ์ œ์•ฝ ๊ด€๊ณ„ ์Šคํ‚ค๋งˆ์˜ ์ผ๋ถ€๋กœ ์„ ์–ธ๋˜์–ด ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์„ ๊ตฌ์ฒด์ ์œผ๋กœ ์ •์˜
ํ‘œํ˜„ ๋ฐฉ๋ฒ• ๊ด€๊ณ„ ๋ชจ๋ธ์˜ ๋…ผ๋ฆฌ์  ๊ทœ์น™์œผ๋กœ, ์ฃผ๋กœ ๊ด€๊ณ„ ๋Œ€์ˆ˜์™€ ์ง‘ํ•ฉ ์ด๋ก ์œผ๋กœ ํ‘œํ˜„ ๊ด€๊ณ„ ์Šคํ‚ค๋งˆ ์ •์˜ ๋‚ด์—์„œ ํŠน์ • ์†์„ฑ ๊ฐ„์˜ ํฌํ•จ ๊ด€๊ณ„๋ฅผ ํ˜•์‹์ ์œผ๋กœ ํ‘œํ˜„

์˜ˆ์‹œ: ๊ด€๊ณ„ ๋ชจ๋ธ์—์„œ์˜ ํ‘œํ˜„

  1. ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์˜ ์ •์˜:

    ๊ด€๊ณ„ Student์™€ Department๊ฐ€ ์กด์žฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

    ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค:

    $$ \pi_{department\id}(Student) \subseteq \pi{department\_id}(Department) $$

  2. ์™ธ๋ž˜ ํ‚ค ์ œ์•ฝ ์กฐ๊ฑด:

    ์™ธ๋ž˜ ํ‚ค ์ œ์•ฝ ์กฐ๊ฑด์€ ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์„ ์Šคํ‚ค๋งˆ์— ๊ตฌ์ฒด์ ์œผ๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค:

    $$ \text{FOREIGN KEY }(department\_id) \text{ REFERENCES } Department(department\_id) $$


์š”์•ฝํ•˜๋ฉด, ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์€ ๊ด€๊ณ„ ๊ฐ„ ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์›์น™์  ๊ฐœ๋…์ด๊ณ , ์™ธ๋ž˜ ํ‚ค ์ œ์•ฝ ์กฐ๊ฑด์€ ์ด ์›์น™์„ ๊ด€๊ณ„ ์Šคํ‚ค๋งˆ์— ๊ตฌ์ฒด์ ์œผ๋กœ ์„ ์–ธํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. Relational Model์—์„œ๋Š” ์ด ๋‘ ๊ฐœ๋…์ด ๋…ผ๋ฆฌ์  ์„ค๊ณ„์™€ ํ˜•์‹์  ์ •์˜๋กœ ๊ตฌ๋ถ„๋ฉ๋‹ˆ๋‹ค.