Mid-term

1๏ธโƒฃย ๊ฐœ์ธ ์ •๋ฆฌ

notion image
์ด ๋‹ค์ด์–ด๊ทธ๋žจ์€ **DBMS (Database Management System)**์˜ ๊ตฌ์„ฑ ๋ชจ๋“ˆ์„ ์„ค๋ช…ํ•˜๊ณ  ์žˆ๋‹ค. ๊ฐ๊ฐ์˜ ์ฃผ์š” ๋ชจ๋“ˆ๊ณผ ํ๋ฆ„์„ ์„ค๋ช…ํ•ด ๋ณด๊ฒ ๋‹ค.

1. ์‚ฌ์šฉ์ž ์ข…๋ฅ˜ (Users)

  • DBA Staff: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ด€๋ฆฌ์ž (DBA)๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด๋“ค. ์ฃผ๋กœ ๋ฐ์ดํ„ฐ ์ •์˜ ์–ธ์–ด(DDL)๋ฅผ ์‚ฌ์šฉํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ตฌ์กฐ๋ฅผ ์ •์˜ํ•˜๊ณ  ๊ด€๋ฆฌํ•œ๋‹ค.
  • Casual Users: ์ฃผ๊ธฐ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž๋“ค๋กœ, ๋Œ€ํ™”ํ˜• ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์ˆ˜์ •ํ•œ๋‹ค.
  • Application Programmers: ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•˜๋Š” ํ”„๋กœ๊ทธ๋ž˜๋จธ๋“ค๋กœ, DB์™€ ์—ฐ๋™๋œ ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•œ๋‹ค.
  • Parametric Users: ์ฃผ๋กœ ๋ฏธ๋ฆฌ ์ปดํŒŒ์ผ๋œ ํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ ์‚ฌ์šฉ์ž๋“ค๋กœ, ์˜ˆ๋ฅผ ๋“ค์–ด, ์€ํ–‰์˜ ์€ํ–‰์› ๋“ฑ์ด ์žˆ๋‹ค.

2. ๋ช…๋ น์–ด ํ๋ฆ„ (Commands and Processes)

  • DDL Statements: ๋ฐ์ดํ„ฐ ์ •์˜ ์–ธ์–ด ๋ช…๋ น์–ด๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์Šคํ‚ค๋งˆ๋ฅผ ์ •์˜ํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•˜๋Š” ๋ช…๋ น์–ด๋‹ค.
    • DDL Compiler: DDL ๋ช…๋ น์–ด๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๊ตฌ์กฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.
  • Interactive Query: ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž๊ฐ€ ๋Œ€ํ™”ํ˜•์œผ๋กœ ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค. ์‚ฌ์šฉ์ž๋Š” ์ฃผ๋กœ SQL ๋ฌธ์„ ์ง์ ‘ ์ž…๋ ฅํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ ์กฐ์ž‘ํ•œ๋‹ค.
    • Query Compiler: ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ SQL ์ฟผ๋ฆฌ๋ฅผ ์ปดํŒŒ์ผํ•˜์—ฌ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.
    • Query Optimizer: ์ฟผ๋ฆฌ์˜ ์„ฑ๋Šฅ์„ ์ตœ์ ํ™”ํ•˜๋Š” ๋‹จ๊ณ„๋กœ, ์ตœ์ ์˜ ๊ฒฝ๋กœ๋ฅผ ์ฐพ์•„ ํšจ์œจ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค€๋‹ค.
  • Application Programs: ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ์ž‘์„ฑํ•œ ํ”„๋กœ๊ทธ๋žจ์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค.
    • Precompiler: ํ”„๋กœ๊ทธ๋žจ ๋‚ด์—์„œ ์‚ฌ์šฉ๋œ SQL ๋ฌธ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ณ€ํ™˜ํ•œ๋‹ค.
    • DML Compiler: ๋ฐ์ดํ„ฐ ์กฐ์ž‘ ์–ธ์–ด(DML) ๋ช…๋ น์–ด๋ฅผ ์ปดํŒŒ์ผํ•˜์—ฌ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ๋ช…๋ น์–ด๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.
  • Compiled Transactions: ๋ฏธ๋ฆฌ ์ปดํŒŒ์ผ๋œ ํŠธ๋žœ์žญ์…˜์€ ํŒŒ๋ผ๋ฉ”ํŠธ๋ฆญ ์‚ฌ์šฉ์ž๋“ค์ด ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋ฐ˜๋ณต์ ์œผ๋กœ ๋™์ผํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.

3. ์ €์žฅ์†Œ ๊ด€๋ จ ๋ชจ๋“ˆ (Storage Modules)

  • Runtime Database Processor: ์‹ค์ œ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์ฟผ๋ฆฌ๋‚˜ ํŠธ๋žœ์žญ์…˜์„ ์‹คํ–‰ํ•˜๋Š” ์ฒ˜๋ฆฌ๊ธฐ๋‹ค.
  • Concurrency Control/Backup/Recovery Subsystems: ๋™์‹œ์„ฑ ์ œ์–ด์™€ ๋ฐฑ์—…, ๋ณต๊ตฌ ์‹œ์Šคํ…œ์„ ๋‹ด๋‹นํ•˜์—ฌ ๋‹ค์ค‘ ์‚ฌ์šฉ์ž ํ™˜๊ฒฝ์—์„œ๋„ ๋ฐ์ดํ„ฐ์˜ ๋ฌด๊ฒฐ์„ฑ์„ ๋ณด์žฅํ•œ๋‹ค.
  • Stored Data Manager: ๋ฌผ๋ฆฌ์ ์œผ๋กœ ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ชจ๋“ˆ๋กœ, ๋””์Šคํฌ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๊ณ  ์“ฐ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

4. ์ €์žฅ ๋ฐ์ดํ„ฐ (Stored Database)

  • Stored Database: ์‹ค์ œ๋กœ ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ, ์—ฌ๊ธฐ์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ๋‹ค.
  • System Catalog/Data Dictionary: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ณณ์ด๋‹ค. ํ…Œ์ด๋ธ”์˜ ๊ตฌ์กฐ, ๊ด€๊ณ„, ์ธ๋ฑ์Šค ๋“ฑ์˜ ์ •๋ณด๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋‹ค.
์ด ๋‹ค์ด์–ด๊ทธ๋žจ์€ DBMS์˜ ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž ๊ณ„์ธต๊ณผ ๊ทธ๋“ค์ด ์‚ฌ์šฉํ•˜๋Š” ๋‹ค์–‘ํ•œ ๋ช…๋ น์–ด ๋ฐ ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ์–ด๋–ป๊ฒŒ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌ๋˜๊ณ  ์šด์˜๋˜๋Š”์ง€ ์„ค๋ช…ํ•˜๊ณ  ์žˆ๋‹ค.
ย 
notion image
์ด ์Šฌ๋ผ์ด๋“œ๋Š” ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ "๊ด€๊ณ„" ๋˜๋Š” "๊ด€๊ณ„ ์ƒํƒœ"๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์„ค๋ช…ํ•˜๊ณ  ์žˆ๋‹ค. ๊ฐ ์š”์†Œ๋ฅผ ์„ค๋ช…ํ•ด๋ณด๊ฒ ๋‹ค.

1. Relation (or Relation State) \( r(R) \): ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒํƒœ

  • ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๊ด€๊ณ„๋ž€ ํ…Œ์ด๋ธ”๊ณผ ๋™์ผํ•œ ๊ฐœ๋…์œผ๋กœ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ด€๊ณ„๋Š” ์ˆ˜ํ•™์  ๊ด€๊ณ„๋กœ ํ‘œํ˜„๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์—ฌ๋Ÿฌ ์†์„ฑ(Attribute)์œผ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. ๊ฐ๊ฐ์˜ ์†์„ฑ์€ ํŠน์ • ๋„๋ฉ”์ธ(Domain) ๋‚ด์˜ ๊ฐ’์„ ๊ฐ€์ง„๋‹ค.

2. Mathematical Relation

  • ์ˆ˜ํ•™์ ์ธ ๊ด€์ ์—์„œ, ๊ด€๊ณ„๋Š” ํŠน์ • ๋„๋ฉ”์ธ์—์„œ ์ •์˜๋œ n์ฐจ์› ํ–‰๋ ฌ์ด๋‹ค. ์—ฌ๊ธฐ์„œ n์€ ์†์„ฑ(์ปฌ๋Ÿผ)์˜ ๊ฐœ์ˆ˜๋‹ค.
  • \( dom(A_1), dom(A_2), \dots, dom(A_n) \)๋Š” ๊ฐ ์†์„ฑ๋“ค์ด ๊ฐ€์ง€๋Š” ๊ฐ’์˜ ๋ฒ”์œ„(๋„๋ฉ”์ธ)๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.

3. Subset of Cartesian Product

  • ๊ด€๊ณ„๋Š” ์—ฌ๋Ÿฌ ์†์„ฑ์˜ ๋„๋ฉ”์ธ๋“ค์˜ **๋ฐ์นด๋ฅดํŠธ ๊ณฑ(Cartesian Product)**์˜ ๋ถ€๋ถ„ ์ง‘ํ•ฉ์œผ๋กœ ์ •์˜๋œ๋‹ค.
  • ์ด๋ฅผ ์ˆ˜์‹์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋ฉด \( r(R) \subseteq (dom(A_1) \times dom(A_2) \times \dots \times dom(A_n)) \)์ด๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค์–ด, ์†์„ฑ์ด 3๊ฐœ์ธ ๊ฒฝ์šฐ, A1์˜ ๋„๋ฉ”์ธ, A2์˜ ๋„๋ฉ”์ธ, A3์˜ ๋„๋ฉ”์ธ์˜ ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์€ ์ด ์„ธ ๋„๋ฉ”์ธ์˜ ๋ชจ๋“  ๊ฐ€๋Šฅํ•œ ์กฐํ•ฉ์„ ํฌํ•จํ•œ๋‹ค. ํ•˜์ง€๋งŒ ๊ด€๊ณ„๋Š” ๊ทธ ์ค‘ ์ผ๋ถ€ ์กฐํ•ฉ๋งŒ์„ ํฌํ•จํ•˜๊ฒŒ ๋œ๋‹ค.

4. ํ…Œ์ด๋ธ” ํ˜•์‹์œผ๋กœ ํ‘œํ˜„๋œ ๊ด€๊ณ„

  • ๊ทธ๋ฆผ์—์„œ ๋ณด๋“ฏ์ด, ๊ด€๊ณ„๋Š” ํ‘œ(ํ…Œ์ด๋ธ”) ํ˜•ํƒœ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค.
  • A1, A2, A3, โ€ฆ, An์€ ํ…Œ์ด๋ธ”์˜ ์—ด(์†์„ฑ)์„ ๋‚˜ํƒ€๋‚ด๊ณ , ๊ฐ ์—ด์€ ํŠน์ • ๋„๋ฉ”์ธ์—์„œ ๊ฐ’์„ ๊ฐ€์ง„๋‹ค.
  • ๊ฐ ํ–‰(row)์€ ์†์„ฑ๋“ค ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ, ์ด ํ–‰๋“ค์ด ๋ฐ”๋กœ ๊ด€๊ณ„ \( r(R) \)๋ฅผ ๊ตฌ์„ฑํ•œ๋‹ค.

์š”์•ฝ:

  • ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ "๊ด€๊ณ„"๋Š” ์—ฌ๋Ÿฌ ์†์„ฑ๋“ค ๊ฐ„์˜ ์—ฐ๊ด€์„ฑ์„ ๋‚˜ํƒ€๋‚ด๋ฉฐ, ์ด๋Š” ์ˆ˜ํ•™์ ์œผ๋กœ ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ์œผ๋กœ ํ‘œํ˜„๋œ๋‹ค.
  • ํ…Œ์ด๋ธ”์€ ์†์„ฑ๋“ค์˜ ๋„๋ฉ”์ธ ๋‚ด ๊ฐ’๋“ค์˜ ์กฐํ•ฉ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉฐ, ํ…Œ์ด๋ธ”์˜ ๊ฐ ํ–‰์€ ๊ด€๊ณ„ ์ƒํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.
์ด๋ฅผ ํ†ตํ•ด ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๊ธฐ๋ณธ ๊ตฌ์กฐ์™€ ๊ด€๊ณ„์˜ ์ˆ˜ํ•™์  ์ •์˜๋ฅผ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค.
ย 
์ด ์„ค๋ช…์€ **์ˆ˜ํ•™์  ๊ด€๊ณ„(Relation)**์— ๋Œ€ํ•œ ์ •์˜๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์œผ๋กœ, ํŠนํžˆ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ์˜ ๊ด€๊ณ„๋ฅผ ์„ค๋ช…ํ•˜๊ณ  ์žˆ๋‹ค. ์ด๋ฅผ ๋‹จ๊ณ„๋ณ„๋กœ ํ’€์–ด์„œ ์„ค๋ช…ํ•ด ๋ณด๊ฒ ๋‹ค.

1. ์ˆ˜ํ•™์  ๊ด€๊ณ„์˜ ์ •์˜

  • *"Mathematical relation of degree n"**๋Š” **n๊ฐœ์˜ ์†์„ฑ(Attributes)**์„ ๊ฐ€์ง„ ์ˆ˜ํ•™์  ๊ด€๊ณ„๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ์—ฌ๊ธฐ์„œ n์€ ๊ด€๊ณ„์˜ ์ฐจ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ฆ‰, ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ”(๊ด€๊ณ„)์— ์†์„ฑ(์ปฌ๋Ÿผ)์ด n๊ฐœ ์žˆ์„ ๋•Œ, ์ด๋ฅผ "n์ฐจ ๊ด€๊ณ„"๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
  • ๊ฐ ์†์„ฑ์€ ํŠน์ • **๋„๋ฉ”์ธ(Domain)**์—์„œ ๊ฐ’์„ ๊ฐ€์ง„๋‹ค. ๋„๋ฉ”์ธ์€ ์†์„ฑ์˜ ๊ฐ’์ด ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ’์˜ ๋ฒ”์œ„๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค์–ด, dom(A1)์€ ์†์„ฑ A1์ด ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ’๋“ค์˜ ์ง‘ํ•ฉ์ด๋‹ค.

2. ๋ฐ์นด๋ฅดํŠธ ๊ณฑ(Cartesian Product)

  • ์„ค๋ช…์— ๋‚˜์˜จ **"Subset of the Cartesian product of the domains"**๋ผ๋Š” ๊ตฌ๋ฌธ์€ ๊ด€๊ณ„๊ฐ€ ์—ฌ๋Ÿฌ ์†์„ฑ์˜ ๋„๋ฉ”์ธ ๊ฐ„์˜ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์กฐํ•ฉ์œผ๋กœ๋ถ€ํ„ฐ ์ผ๋ถ€๋ฅผ ์„ ํƒํ•œ ๊ฒƒ์ด๋ผ๋Š” ์˜๋ฏธ๋‹ค.
  • ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์€ ์—ฌ๋Ÿฌ ์ง‘ํ•ฉ์˜ ๋ชจ๋“  ๊ฐ€๋Šฅํ•œ ์กฐํ•ฉ์„ ๋งŒ๋“œ๋Š” ์—ฐ์‚ฐ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋‘ ๊ฐœ์˜ ์ง‘ํ•ฉ A์™€ B๊ฐ€ ์žˆ์„ ๋•Œ, ๊ทธ๋“ค์˜ ๋ฐ์นด๋ฅดํŠธ ๊ณฑ \( A \times B \)๋Š” A์™€ B์—์„œ ํ•˜๋‚˜์”ฉ ๊ฐ’์„ ๋ฝ‘์•„ ๋งŒ๋“  ๋ชจ๋“  ์ˆœ์„œ์Œ์„ ํฌํ•จํ•œ๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค์–ด, \( A = \{1, 2\}, B = \{x, y\} \)์ผ ๋•Œ, \( A \times B = \{(1, x), (1, y), (2, x), (2, y)\} \)๊ฐ€ ๋œ๋‹ค.

3. **๊ด€๊ณ„ \( r(R) \)๋Š” ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ

  • *r(R) โŠ† (dom(A1) ร— dom(A2) ร— ... ร— dom(An))**๋Š” ๊ด€๊ณ„ \( r(R) \)๊ฐ€ ๊ฐ ์†์„ฑ์˜ ๋„๋ฉ”์ธ \( dom(A1), dom(A2), \dots, dom(An) \)์˜ ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ์ด๋ผ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.
  • ๋ฌด์Šจ ๋œป์ด๋ƒ๋ฉด:
    • \( dom(A1) ร— dom(A2) ร— ... ร— dom(An) \)์€ ๊ฐ ์†์„ฑ์˜ ๋„๋ฉ”์ธ์—์„œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฐ’์˜ ์กฐํ•ฉ์„ ์˜๋ฏธํ•œ๋‹ค. ์ด ๋ชจ๋“  ์กฐํ•ฉ์ด ์ด๋ฃจ์–ด์ง„ ๊ฒƒ์ด ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์ด๋‹ค.
    • *r(R)**๋Š” ๊ทธ ๋ชจ๋“  ์กฐํ•ฉ ์ค‘์—์„œ ์‹ค์ œ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”์— ๋“ค์–ด ์žˆ๋Š” ๊ฐ’๋“ค์˜ ์ง‘ํ•ฉ, ์ฆ‰ ํ…Œ์ด๋ธ”์˜ ํ–‰(row)๋“ค์ด ํฌํ•จ๋œ ๋ถ€๋ถ„์ง‘ํ•ฉ์ด๋‹ค.

์˜ˆ์‹œ๋กœ ํ’€์–ด์„œ ์„ค๋ช…

  • ์˜ˆ๋ฅผ ๋“ค์–ด, ํ…Œ์ด๋ธ”์ด ๋‘ ๊ฐœ์˜ ์†์„ฑ \( A1 \)๊ณผ \( A2 \)๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค๊ณ  ํ•ด๋ณด์ž.
    • \( dom(A1) = \{1, 2\}, dom(A2) = \{x, y\} \)๋ผ๊ณ  ํ•  ๋•Œ, ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์€ \( dom(A1) ร— dom(A2) = \{(1, x), (1, y), (2, x), (2, y)\} \)๊ฐ€ ๋œ๋‹ค.
    • ๊ทธ๋Ÿฌ๋‚˜ ์‹ค์ œ๋กœ ํ…Œ์ด๋ธ”์— ์ €์žฅ๋œ ๊ฐ’์ด \( (1, x), (2, y) \)๋งŒ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด, **r(R)**๋Š” \( \{(1, x), (2, y)\} \)๋กœ ํ‘œํ˜„๋œ๋‹ค. ์ด๋Š” ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ์ด๋‹ค.

์š”์•ฝ

  • *๊ด€๊ณ„ \( r(R) \)**๋Š” ์†์„ฑ๋“ค ๊ฐ„์˜ ์กฐํ•ฉ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ํ…Œ์ด๋ธ”์˜ ํ–‰๋“ค์„ ๋‚˜ํƒ€๋‚ด๋ฉฐ, ๊ฐ ์†์„ฑ์€ ๋„๋ฉ”์ธ์ด๋ผ๋Š” ๊ฐ’์˜ ๋ฒ”์œ„์—์„œ ๊ฐ’์„ ๊ฐ€์ง„๋‹ค.
  • ์ด ๊ด€๊ณ„๋Š” ๋ฐ์นด๋ฅดํŠธ ๊ณฑ์˜ ๋ชจ๋“  ๊ฐ€๋Šฅํ•œ ์กฐํ•ฉ ์ค‘์—์„œ ์‹ค์ œ๋กœ ํ…Œ์ด๋ธ”์— ์กด์žฌํ•˜๋Š” ๊ฐ’๋“ค์˜ ๋ถ€๋ถ„์ง‘ํ•ฉ์ด๋‹ค.
ย 
notion image
์ด ์Šฌ๋ผ์ด๋“œ๋Š” ๊ด€๊ณ„ ์ œ์•ฝ์กฐ๊ฑด์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ํ…Œ์ด๋ธ” ๊ฐ„์˜ ๋ฌด๊ฒฐ์„ฑ๊ณผ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์ ์šฉ๋˜๋Š” ๋‹ค์–‘ํ•œ ์ œ์•ฝ์กฐ๊ฑด๋“ค์„ ์„ค๋ช…ํ•˜๊ณ  ์žˆ๋‹ค. ๊ฐ๊ฐ์˜ ์ œ์•ฝ์กฐ๊ฑด์„ ๋ถ„์„ํ•ด ๋ณด๊ฒ ๋‹ค.

1. ๋„๋ฉ”์ธ ์ œ์•ฝ์กฐ๊ฑด (Domain Constraints)

  • ์ •์˜: ๊ฐ ํ•„๋“œ์˜ ๊ฐ’์ด ํ•ด๋‹น ํ•„๋“œ์˜ ๋„๋ฉ”์ธ(์ฆ‰, ๊ทธ ํ•„๋“œ์—์„œ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ’์˜ ๋ฒ”์œ„)์— ์†ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ œ์•ฝ์ด๋‹ค.
  • ์˜ˆ์‹œ: ์Šฌ๋ผ์ด๋“œ์˜ ์˜ˆ์‹œ์—์„œ, MgrStartDate ํ•„๋“œ๋Š” ๋‚ ์งœ(Date) ํƒ€์ž…์ด์–ด์•ผ ํ•œ๋‹ค๋Š” ๋„๋ฉ”์ธ ์ œ์•ฝ์กฐ๊ฑด์ด ์ ์šฉ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ์ด ํ•„๋“œ์—๋Š” ๋ฐ˜๋“œ์‹œ ๋‚ ์งœ ํ˜•์‹์˜ ๊ฐ’๋งŒ ๋“ค์–ด๊ฐ€์•ผ ํ•œ๋‹ค.

2. ํ‚ค ์ œ์•ฝ์กฐ๊ฑด (Key Constraints)

  • ์ •์˜: ํ‚ค ์ œ์•ฝ์กฐ๊ฑด์€ ํ…Œ์ด๋ธ”์˜ ๊ฐ ํ–‰์ด ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„๋  ์ˆ˜ ์žˆ๋„๋ก ๊ธฐ๋ณธ ํ‚ค ๋˜๋Š” ํ›„๋ณด ํ‚ค๊ฐ€ ์„ค์ •๋˜์–ด์•ผ ํ•œ๋‹ค๋Š” ์ œ์•ฝ์ด๋‹ค.
  • ์˜ˆ์‹œ: Employee ํ…Œ์ด๋ธ”์˜ SSN(์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ) ํ•„๋“œ๋Š” ๊ธฐ๋ณธ ํ‚ค๋กœ ์‚ฌ์šฉ๋˜์–ด, ๊ฐ ์ง์›์ด ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„๋  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. Department ํ…Œ์ด๋ธ”์˜ DNUMBER๋„ ๊ณ ์œ ํ•œ ๊ฐ’์ด์–ด์•ผ ํ•œ๋‹ค.

3. ์—”ํ„ฐํ‹ฐ ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ์กฐ๊ฑด (Entity Integrity Constraints)

  • ์ •์˜: ๊ธฐ๋ณธ ํ‚ค๋Š” ์ ˆ๋Œ€๋กœ NULL ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์—†๋‹ค๋Š” ์ œ์•ฝ์ด๋‹ค. ๊ธฐ๋ณธ ํ‚ค๋Š” ํ…Œ์ด๋ธ” ๋‚ด์—์„œ ๊ฐ ํ–‰์„ ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„ํ•˜๋Š” ์—ญํ• ์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ˜๋“œ์‹œ ๊ฐ’์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.
  • ์˜ˆ์‹œ: SSN ํ•„๋“œ๋Š” ๊ธฐ๋ณธ ํ‚ค์ด๋ฏ€๋กœ ์ ˆ๋Œ€๋กœ NULL ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์—†๋‹ค.

4. ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ์กฐ๊ฑด (Referential Integrity Constraints)

  • ์ •์˜: ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ์กฐ๊ฑด์€ ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์ฐธ์กฐํ•˜๋Š” ํ…Œ์ด๋ธ”์˜ ๊ธฐ๋ณธ ํ‚ค๊ฐ€ ๋ฐ˜๋“œ์‹œ ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ œ์•ฝ์ด๋‹ค. ์ฆ‰, ํ•œ ํ…Œ์ด๋ธ”์—์„œ ์™ธ๋ž˜ ํ‚ค๋กœ ์‚ฌ์šฉ๋œ ๊ฐ’์€ ๋ฐ˜๋“œ์‹œ ์ฐธ์กฐํ•˜๋Š” ํ…Œ์ด๋ธ”์— ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค.
  • ์˜ˆ์‹œ: Department ํ…Œ์ด๋ธ”์˜ MgrSSN(๊ด€๋ฆฌ์ž ์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ) ํ•„๋“œ๋Š” Employee ํ…Œ์ด๋ธ”์˜ SSN ํ•„๋“œ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ์™ธ๋ž˜ ํ‚ค์ด๋‹ค. ๋”ฐ๋ผ์„œ MgrSSN์— ์ž…๋ ฅ๋œ ๊ฐ’์€ ๋ฐ˜๋“œ์‹œ Employee ํ…Œ์ด๋ธ”์˜ SSN ํ•„๋“œ์—์„œ ์œ ํšจํ•œ ๊ฐ’์ด์–ด์•ผ ํ•œ๋‹ค.

์š”์•ฝ

์ด ์Šฌ๋ผ์ด๋“œ๋Š” ๋„๋ฉ”์ธ ์ œ์•ฝ์กฐ๊ฑด, ํ‚ค ์ œ์•ฝ์กฐ๊ฑด, ์—”ํ„ฐํ‹ฐ ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ์กฐ๊ฑด, ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ ์ œ์•ฝ์กฐ๊ฑด์„ ์„ค๋ช…ํ•˜๋ฉฐ, ๊ฐ ์ œ์•ฝ์กฐ๊ฑด์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ผ๊ด€์„ฑ์„ ๋ณด์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค€๋‹ค.
  • ๋„๋ฉ”์ธ ์ œ์•ฝ์กฐ๊ฑด์€ ํ•„๋“œ ๊ฐ’์˜ ํƒ€์ž…์ด๋‚˜ ๋ฒ”์œ„๋ฅผ ์ œํ•œํ•˜๊ณ ,
  • ํ‚ค ์ œ์•ฝ์กฐ๊ฑด์€ ๊ฐ ํ–‰์„ ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„ํ•˜๋ฉฐ,
  • ์—”ํ„ฐํ‹ฐ ๋ฌด๊ฒฐ์„ฑ์€ ๊ธฐ๋ณธ ํ‚ค์— NULL ๊ฐ’์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๊ณ ,
  • ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์€ ์™ธ๋ž˜ ํ‚ค๊ฐ€ ์ฐธ์กฐํ•˜๋Š” ํ…Œ์ด๋ธ”์˜ ๊ฐ’๊ณผ ์ผ์น˜ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ œ์•ฝ์„ ์„ค์ •ํ•œ๋‹ค.
ย 

-- EMPLOYEE ํ…Œ์ด๋ธ” ์ƒ์„ฑ CREATE TABLE EMPLOYEE ( FNAME VARCHAR(15) NOT NULL, -- ์ง์›์˜ ์ด๋ฆ„, 15์ž๊นŒ์ง€ ์ €์žฅ ๊ฐ€๋Šฅํ•˜๋ฉฐ NULL ๋ถˆ๊ฐ€ MINIT CHAR, -- ์ค‘๊ฐ„ ์ด๋‹ˆ์…œ, ๋ฌธ์ž 1๊ฐœ LNAME VARCHAR(15) NOT NULL, -- ์ง์›์˜ ์„ฑ, 15์ž๊นŒ์ง€ ์ €์žฅ ๊ฐ€๋Šฅํ•˜๋ฉฐ NULL ๋ถˆ๊ฐ€ SSN CHAR(9) NOT NULL, -- ์ง์›์˜ ์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ, 9์ž๋ฆฌ๋กœ NULL ๋ถˆ๊ฐ€ BDATE DATE, -- ์ง์›์˜ ์ƒ๋…„์›”์ผ ADDRESS VARCHAR(30), -- ์ง์›์˜ ์ฃผ์†Œ, ์ตœ๋Œ€ 30์ž SEX CHAR, -- ์„ฑ๋ณ„, ๋ฌธ์ž 1๊ฐœ SALARY DECIMAL(10, 2) DEFAULT 3000, -- ๊ธ‰์—ฌ, ์†Œ์ˆ˜์  ๋‘˜์งธ ์ž๋ฆฌ๊นŒ์ง€ ํ‘œํ˜„, ๊ธฐ๋ณธ๊ฐ’์€ 3000 SUPERSSN CHAR(9), -- ์ƒ์‚ฌ์˜ ์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ (์™ธ๋ž˜ ํ‚ค๋กœ ์ฐธ์กฐ ๊ฐ€๋Šฅ) DNO INT NOT NULL DEFAULT 1, -- ๋ถ€์„œ ๋ฒˆํ˜ธ (์™ธ๋ž˜ ํ‚ค๋กœ ์ฐธ์กฐ ๊ฐ€๋Šฅ), NULL ๋ถˆ๊ฐ€, ๊ธฐ๋ณธ๊ฐ’์€ 1 PRIMARY KEY (SSN), -- SSN์„ ๊ธฐ๋ณธ ํ‚ค๋กœ ์„ค์ • (๊ณ ์œ  ๊ฐ’) FOREIGN KEY (SUPERSSN) REFERENCES EMPLOYEE(SSN) ON DELETE SET NULL -- ์ƒ์‚ฌ ์ •๋ณด๊ฐ€ ์‚ญ์ œ๋  ๊ฒฝ์šฐ NULL๋กœ ์„ค์ • ON UPDATE CASCADE, -- ์ƒ์‚ฌ ์ •๋ณด๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • FOREIGN KEY (DNO) REFERENCES DEPARTMENT(DNUMBER) ON DELETE SET DEFAULT -- ๋ถ€์„œ ์ •๋ณด๊ฐ€ ์‚ญ์ œ๋  ๊ฒฝ์šฐ ๊ธฐ๋ณธ๊ฐ’(DNO=1)์œผ๋กœ ์„ค์ • ON UPDATE CASCADE -- ๋ถ€์„œ ๋ฒˆํ˜ธ๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • ); -- DEPARTMENT ํ…Œ์ด๋ธ” ์ƒ์„ฑ CREATE TABLE DEPARTMENT ( DNAME VARCHAR(15) NOT NULL, -- ๋ถ€์„œ ์ด๋ฆ„, 15์ž๊นŒ์ง€ ์ €์žฅ ๊ฐ€๋Šฅํ•˜๋ฉฐ NULL ๋ถˆ๊ฐ€ DNUMBER INT NOT NULL, -- ๋ถ€์„œ ๋ฒˆํ˜ธ, NULL ๋ถˆ๊ฐ€ MGRSSN CHAR(9) NOT NULL DEFAULT '888665555', -- ๋ถ€์„œ ๊ด€๋ฆฌ์ž์˜ ์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ, ๊ธฐ๋ณธ๊ฐ’ ์„ค์ • MGRSTARTDATE DATE, -- ๋ถ€์„œ ๊ด€๋ฆฌ์ž๊ฐ€ ์‹œ์ž‘ํ•œ ๋‚ ์งœ PRIMARY KEY (DNUMBER), -- DNUMBER๋ฅผ ๊ธฐ๋ณธ ํ‚ค๋กœ ์„ค์ • CHECK (DNUMBER > 0 AND DNUMBER < 21), -- DNUMBER์˜ ๊ฐ’์ด 1~20 ์‚ฌ์ด์—ฌ์•ผ ํ•จ FOREIGN KEY (MGRSSN) REFERENCES EMPLOYEE(SSN) ON DELETE SET DEFAULT -- ๊ด€๋ฆฌ์ž๊ฐ€ ์‚ญ์ œ๋  ๊ฒฝ์šฐ ๊ธฐ๋ณธ๊ฐ’(888665555)์œผ๋กœ ์„ค์ • ON UPDATE CASCADE -- ๊ด€๋ฆฌ์ž๊ฐ€ ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • ); -- DEPT_LOCATIONS ํ…Œ์ด๋ธ” ์ƒ์„ฑ CREATE TABLE DEPT_LOCATIONS ( DNUMBER INT NOT NULL, -- ๋ถ€์„œ ๋ฒˆํ˜ธ (์™ธ๋ž˜ ํ‚ค๋กœ ์ฐธ์กฐ ๊ฐ€๋Šฅ), NULL ๋ถˆ๊ฐ€ DLOCATION VARCHAR(15) NOT NULL, -- ๋ถ€์„œ ์œ„์น˜, 15์ž๊นŒ์ง€ ์ €์žฅ ๊ฐ€๋Šฅํ•˜๋ฉฐ NULL ๋ถˆ๊ฐ€ PRIMARY KEY (DNUMBER, DLOCATION), -- DNUMBER์™€ DLOCATION์˜ ์กฐํ•ฉ์œผ๋กœ ๋ณตํ•ฉ ํ‚ค ์„ค์ • FOREIGN KEY (DNUMBER) REFERENCES DEPARTMENT(DNUMBER) ON DELETE CASCADE -- ๋ถ€์„œ๊ฐ€ ์‚ญ์ œ๋  ๊ฒฝ์šฐ ๋ถ€์„œ ์œ„์น˜ ์ •๋ณด๋„ ์‚ญ์ œ๋จ ON UPDATE CASCADE -- ๋ถ€์„œ ๋ฒˆํ˜ธ๊ฐ€ ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • ); -- PROJECT ํ…Œ์ด๋ธ” ์ƒ์„ฑ CREATE TABLE PROJECT ( PNAME VARCHAR(15) NOT NULL, -- ํ”„๋กœ์ ํŠธ ์ด๋ฆ„, 15์ž๊นŒ์ง€ ์ €์žฅ ๊ฐ€๋Šฅํ•˜๋ฉฐ NULL ๋ถˆ๊ฐ€ PNUMBER INT NOT NULL, -- ํ”„๋กœ์ ํŠธ ๋ฒˆํ˜ธ, NULL ๋ถˆ๊ฐ€ PLOCATION VARCHAR(15), -- ํ”„๋กœ์ ํŠธ ์œ„์น˜, ์ตœ๋Œ€ 15์ž DNUM INT NOT NULL, -- ๋ถ€์„œ ๋ฒˆํ˜ธ, NULL ๋ถˆ๊ฐ€ (์™ธ๋ž˜ ํ‚ค๋กœ ์ฐธ์กฐ ๊ฐ€๋Šฅ) PRIMARY KEY (PNUMBER), -- PNUMBER๋ฅผ ๊ธฐ๋ณธ ํ‚ค๋กœ ์„ค์ • FOREIGN KEY (DNUM) REFERENCES DEPARTMENT(DNUMBER) ON DELETE CASCADE -- ๋ถ€์„œ ์‚ญ์ œ ์‹œ ํ”„๋กœ์ ํŠธ๋„ ์‚ญ์ œ๋จ ON UPDATE CASCADE -- ๋ถ€์„œ ๋ฒˆํ˜ธ ๋ณ€๊ฒฝ ์‹œ ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • ); -- WORKS_ON ํ…Œ์ด๋ธ” ์ƒ์„ฑ CREATE TABLE WORKS_ON ( ESSN CHAR(9) NOT NULL, -- ์ง์›์˜ ์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ (์™ธ๋ž˜ ํ‚ค๋กœ ์ฐธ์กฐ ๊ฐ€๋Šฅ), NULL ๋ถˆ๊ฐ€ PNO INT NOT NULL, -- ํ”„๋กœ์ ํŠธ ๋ฒˆํ˜ธ (์™ธ๋ž˜ ํ‚ค๋กœ ์ฐธ์กฐ ๊ฐ€๋Šฅ), NULL ๋ถˆ๊ฐ€ HOURS DECIMAL(3, 1) NOT NULL, -- ์ž‘์—… ์‹œ๊ฐ„, ์†Œ์ˆ˜์  1์ž๋ฆฌ๊นŒ์ง€ ํ‘œํ˜„, NULL ๋ถˆ๊ฐ€ PRIMARY KEY (ESSN, PNO), -- ESSN๊ณผ PNO์˜ ์กฐํ•ฉ์œผ๋กœ ๋ณตํ•ฉ ํ‚ค ์„ค์ • FOREIGN KEY (ESSN) REFERENCES EMPLOYEE(SSN) ON DELETE CASCADE -- ์ง์›์ด ์‚ญ์ œ๋  ๊ฒฝ์šฐ ์ž‘์—… ์ •๋ณด๋„ ์‚ญ์ œ๋จ ON UPDATE CASCADE, -- ์ง์› SSN์ด ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • FOREIGN KEY (PNO) REFERENCES PROJECT(PNUMBER) ON DELETE CASCADE -- ํ”„๋กœ์ ํŠธ๊ฐ€ ์‚ญ์ œ๋  ๊ฒฝ์šฐ ์ž‘์—… ์ •๋ณด๋„ ์‚ญ์ œ๋จ ON UPDATE CASCADE -- ํ”„๋กœ์ ํŠธ ๋ฒˆํ˜ธ๊ฐ€ ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • ); -- DEPENDENT ํ…Œ์ด๋ธ” ์ƒ์„ฑ CREATE TABLE DEPENDENT ( ESSN CHAR(9) NOT NULL, -- ์ง์›์˜ ์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ (์™ธ๋ž˜ ํ‚ค๋กœ ์ฐธ์กฐ ๊ฐ€๋Šฅ), NULL ๋ถˆ๊ฐ€ DEPENDENT_NAME VARCHAR(15) NOT NULL, -- ๋ถ€์–‘ ๊ฐ€์กฑ ์ด๋ฆ„, ์ตœ๋Œ€ 15์ž, NULL ๋ถˆ๊ฐ€ SEX CHAR, -- ๋ถ€์–‘ ๊ฐ€์กฑ ์„ฑ๋ณ„ BDATE DATE, -- ๋ถ€์–‘ ๊ฐ€์กฑ์˜ ์ƒ๋…„์›”์ผ RELATIONSHIP VARCHAR(8), -- ์ง์›๊ณผ ๋ถ€์–‘ ๊ฐ€์กฑ์˜ ๊ด€๊ณ„, ์ตœ๋Œ€ 8์ž PRIMARY KEY (ESSN, DEPENDENT_NAME), -- ESSN๊ณผ DEPENDENT_NAME์˜ ์กฐํ•ฉ์œผ๋กœ ๋ณตํ•ฉ ํ‚ค ์„ค์ • FOREIGN KEY (ESSN) REFERENCES EMPLOYEE(SSN) ON DELETE CASCADE -- ์ง์›์ด ์‚ญ์ œ๋  ๊ฒฝ์šฐ ๋ถ€์–‘ ๊ฐ€์กฑ ์ •๋ณด๋„ ์‚ญ์ œ๋จ ON UPDATE CASCADE -- ์ง์› SSN์ด ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ • );

์„ค๋ช…:

  1. EMPLOYEE ํ…Œ์ด๋ธ”:
      • ๊ธฐ๋ณธ ํ‚ค: SSN์€ ๊ธฐ๋ณธ ํ‚ค๋กœ ์„ค์ •๋˜์–ด ๊ฐ ์ง์›์„ ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„ํ•ฉ๋‹ˆ๋‹ค.
      • ์™ธ๋ž˜ ํ‚ค:
        • SUPERSSN: ์ƒ์‚ฌ์˜ ์‚ฌํšŒ๋ณด์žฅ๋ฒˆํ˜ธ๋กœ EMPLOYEE ํ…Œ์ด๋ธ”์˜ SSN์„ ์ฐธ์กฐํ•˜๋Š” ์žฌ๊ท€์  ์™ธ๋ž˜ ํ‚ค์ž…๋‹ˆ๋‹ค.
        • DNO: ์ง์›์ด ์†ํ•œ ๋ถ€์„œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ DEPARTMENT ํ…Œ์ด๋ธ”์˜ DNUMBER๋ฅผ ์ฐธ์กฐํ•˜๋Š” ์™ธ๋ž˜ ํ‚ค์ž…๋‹ˆ๋‹ค.
  1. DEPARTMENT ํ…Œ์ด๋ธ”:
      • ๊ธฐ๋ณธ ํ‚ค: DNUMBER๋Š” ๋ถ€์„œ ๋ฒˆํ˜ธ๋กœ์„œ ๊ธฐ๋ณธ ํ‚ค๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉฐ, ๊ฐ ๋ถ€์„œ๋ฅผ ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„ํ•ฉ๋‹ˆ๋‹ค.
      • ์ œ์•ฝ ์กฐ๊ฑด: DNUMBER ๊ฐ’์ด 1์—์„œ 20 ์‚ฌ์ด์—ฌ์•ผ ํ•œ๋‹ค๋Š” CHECK ์ œ์•ฝ ์กฐ๊ฑด์ด ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  1. DEPT_LOCATIONS ํ…Œ์ด๋ธ”:
      • ๋ณตํ•ฉ ํ‚ค: DNUMBER์™€ DLOCATION์˜ ์กฐํ•ฉ์„ ๊ธฐ๋ณธ ํ‚ค๋กœ ์‚ฌ์šฉํ•˜์—ฌ ๋ถ€์„œ ๋ฒˆํ˜ธ์™€ ๋ถ€์„œ ์œ„์น˜์˜ ์กฐํ•ฉ์ด ๊ณ ์œ ํ•˜๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
      • ์™ธ๋ž˜ ํ‚ค: DNUMBER๋Š” DEPARTMENT ํ…Œ์ด๋ธ”์˜ DNUMBER๋ฅผ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค.
  1. PROJECT ํ…Œ์ด๋ธ”:
      • ๊ธฐ๋ณธ ํ‚ค: PNUMBER๋Š” ํ”„๋กœ์ ํŠธ ๋ฒˆํ˜ธ๋กœ ๊ธฐ๋ณธ ํ‚ค์ž…๋‹ˆ๋‹ค.
      • ์™ธ๋ž˜ ํ‚ค: DNUM์€ ํ”„๋กœ์ ํŠธ๊ฐ€ ์†ํ•œ ๋ถ€์„œ๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ, DEPARTMENT ํ…Œ์ด๋ธ”์˜ DNUMBER๋ฅผ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค.
  1. WORKS_ON ํ…Œ์ด๋ธ”:
      • ๋ณตํ•ฉ ํ‚ค: ESSN(์ง์›)๊ณผ PNO(ํ”„๋กœ์ ํŠธ ๋ฒˆํ˜ธ)์˜ ์กฐํ•ฉ์„ ๊ธฐ๋ณธ ํ‚ค๋กœ ์‚ฌ์šฉํ•˜์—ฌ, ๊ฐ ์ง์›์ด ์–ด๋–ค ํ”„๋กœ์ ํŠธ์—์„œ ๋ช‡ ์‹œ๊ฐ„ ์ผํ–ˆ๋Š”์ง€๋ฅผ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.
      • ์™ธ๋ž˜ ํ‚ค: ESSN์€ EMPLOYEE ํ…Œ์ด๋ธ”์˜ SSN์„, PNO๋Š” PROJECT ํ…Œ์ด๋ธ”์˜ PNUMBER๋ฅผ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค.
  1. DEPENDENT ํ…Œ์ด๋ธ”:
      • ๋ณตํ•ฉ ํ‚ค: ESSN(์ง์›)๊ณผ DEPENDENT_NAME(๋ถ€์–‘ ๊ฐ€์กฑ ์ด๋ฆ„)์˜ ์กฐํ•ฉ์„ ๊ธฐ๋ณธ ํ‚ค๋กœ ์‚ฌ์šฉํ•˜์—ฌ ๋ถ€์–‘ ๊ฐ€์กฑ ์ •๋ณด๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
      • ์™ธ๋ž˜ ํ‚ค: ESSN์€ EMPLOYEE ํ…Œ์ด๋ธ”์˜ SSN์„ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค.
ย 
์•„๋ž˜๋Š” PDF์—์„œ (b)๋ถ€ํ„ฐ ์ถ”๊ฐ€๋œ DEFAULT, CASCADE ๋“ฑ์„ ๋ฐ˜์˜ํ•œ SQL ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. ๊ฐ๊ฐ์˜ ์ƒˆ๋กœ์šด ์ œ์•ฝ ์กฐ๊ฑด(DEFAULT, CASCADE ๋“ฑ)์„ ์ถ”๊ฐ€ํ•˜๊ณ , ํ•ด๋‹น ๋ถ€๋ถ„์— ๋Œ€ํ•œ ์ฃผ์„๊ณผ ์„ค๋ช…๋„ ํ•จ๊ป˜ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ถ”๊ฐ€๋œ ์ œ์•ฝ ์กฐ๊ฑด๊ณผ ๋™์ž‘ ์„ค๋ช…:

  1. DEFAULT:
      • EMPLOYEE ํ…Œ์ด๋ธ”:
        • SALARY: ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ 3000์ด ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉฐ, ๊ธ‰์—ฌ๊ฐ€ ์ž…๋ ฅ๋˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์ด ๊ฐ’์ด ์ž๋™์œผ๋กœ ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค.
        • DNO: ๋ถ€์„œ ๋ฒˆํ˜ธ์˜ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ 1์ด ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ง์›์ด ์†Œ์†๋œ ๋ถ€์„œ๋ฅผ ์ž…๋ ฅํ•˜์ง€ ์•Š์œผ๋ฉด ์ž๋™์œผ๋กœ ๋ถ€์„œ ๋ฒˆํ˜ธ 1์ด ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค.
      • DEPARTMENT ํ…Œ์ด๋ธ”:
        • MGRSSN: ๋ถ€์„œ ๊ด€๋ฆฌ์ž์˜ ๊ธฐ๋ณธ๊ฐ’์€ **'888665555'**๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉฐ, ๊ด€๋ฆฌ์ž์˜ SSN์ด ์ž…๋ ฅ๋˜์ง€ ์•Š์œผ๋ฉด ์ด ๊ฐ’์ด ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.
  1. ON DELETE ๋ฐ ON UPDATE CASCADE:
      • ON DELETE CASCADE: ์ฐธ์กฐํ•˜๋Š” ํ…Œ์ด๋ธ”์—์„œ ํ–‰์ด ์‚ญ์ œ๋˜๋ฉด, ํ•ด๋‹น ์™ธ๋ž˜ ํ‚ค๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๋ชจ๋“  ๊ด€๋ จ ๋ฐ์ดํ„ฐ๋„ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, WORKS_ON ํ…Œ์ด๋ธ”์—์„œ ์ง์›์ด ์‚ญ์ œ๋˜๋ฉด ๊ทธ ์ง์›๊ณผ ๊ด€๋ จ๋œ ํ”„๋กœ์ ํŠธ ์ •๋ณด๋„ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.
      • ON DELETE SET NULL: ์ฐธ์กฐํ•˜๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ญ์ œ๋˜์—ˆ์„ ๋•Œ, ์™ธ๋ž˜ ํ‚ค ํ•„๋“œ๊ฐ€ NULL๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ƒ์‚ฌ๊ฐ€ ์‚ญ์ œ๋˜๋ฉด ์ง์›์˜ ์ƒ์‚ฌ ์ •๋ณด๋Š” NULL๋กœ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.
      • ON DELETE SET DEFAULT: ์ฐธ์กฐํ•˜๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ญ์ œ๋˜์—ˆ์„ ๋•Œ, ์™ธ๋ž˜ ํ‚ค ํ•„๋“œ๊ฐ€ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ถ€์„œ๊ฐ€ ์‚ญ์ œ๋˜๋ฉด ์ง์›์˜ ๋ถ€์„œ ๋ฒˆํ˜ธ๋Š” ๊ธฐ๋ณธ๊ฐ’์ธ 1๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.
      • ON UPDATE CASCADE: ์ฐธ์กฐํ•˜๋Š” ํ…Œ์ด๋ธ”์—์„œ ๊ธฐ๋ณธ ํ‚ค๊ฐ€ ์ˆ˜์ •๋˜๋ฉด, ๊ทธ ํ‚ค๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๋ชจ๋“  ์™ธ๋ž˜ ํ‚ค ๊ฐ’๋„ ์—ฐ์‡„์ ์œผ๋กœ ์ˆ˜์ •๋ฉ๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ์ œ์•ฝ ์กฐ๊ฑด๋“ค์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์„ ์œ ์ง€ํ•˜๊ณ , ํ…Œ์ด๋ธ” ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ๋ช…ํ™•ํžˆ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ย 

(SELECT PNUMBER FROM PROJECT, DEPARTMENT, EMPLOYEE WHERE DNUM = DNUMBER AND MGRSSN = SSN AND LNAME = 'Smith') UNION (SELECT PNUMBER FROM PROJECT, WORKS_ON, EMPLOYEE WHERE PNUMBER = PNO AND ESSN = SSN AND LNAME = 'Smith');
-- ์ˆ˜์ •๋œ ์ฟผ๋ฆฌ: ๋ช…์‹œ์ ์ธ JOIN๊ณผ ์ •ํ™•ํ•œ ์กฐ๊ฑด ์‚ฌ์šฉ (SELECT PNUMBER FROM PROJECT INNER JOIN DEPARTMENT ON PROJECT.DNUM = DEPARTMENT.DNUMBER INNER JOIN EMPLOYEE ON DEPARTMENT.MGRSSN = EMPLOYEE.SSN WHERE EMPLOYEE.LNAME = 'Smith') UNION (SELECT PNUMBER FROM PROJECT INNER JOIN WORKS_ON ON PROJECT.PNUMBER = WORKS_ON.PNO INNER JOIN EMPLOYEE ON WORKS_ON.ESSN = EMPLOYEE.SSN WHERE EMPLOYEE.LNAME = 'Smith');
ย 

2๏ธโƒฃย ์š”์•ฝ ์ •๋ฆฌ

  1. ๋งŒ์•ฝ ์†์„ฑ์œผ๋กœ ์ €์žฅํ•œ๋‹ค๋ฉด ์ผ์ผ์ด ์ˆ˜ ๋งŽ์€ ์ฑ…์— ์ถœํŒ์‚ฌ์— ๋Œ€ ํ•œ ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ๋˜๋ฉด ๋ฐ์ดํ„ฐ๊ฐ€ ์ค‘๋ณต์œผ๋กœ ์ € ์žฅ๋˜์–ด ์ •ํ™•์„ฑ๊ณผ ์ผ๊ด€์„ฑ์ด ๊ฒฐ์—ฌ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๊ณ , ์ถœํŒ์‚ฌ ์ •๋ณด๊ฐ€ ๋ฐ”๋€” ๊ฒฝ์šฐ ์ฐจํ›„ ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ ๋ถˆํŽธํ•˜๊ฒŒ ๋œ๋‹ค ๋˜ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์˜ ์šฉ๋Ÿ‰์ฆ๊ฐ€, ์ „๋ฐ˜์ ์ธ ์ƒ‰์ธ ์†๋„ ์ €ํ•˜, ์ œ์ž‘ ์‹œ๊ฐ„๋“ฑ์ด ์˜ค๋ž˜ ๊ฑธ๋ฆฐ ๋‹ค๋Š” ๋ฌธ์ œ์ ์ด ์žˆ๋‹ค.
  1. ํ•œ ์ €์ž๊ฐ€ ๋‹ค์ˆ˜์˜ ์ฑ…์„ ์ถœํŒ ํ–ˆ์„ ์ˆ˜ ์žˆ๊ณ , ๊ฐ™์€ ์ฑ…์ด ์—ฌ๋Ÿฌ๊ถŒ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. ๋˜ ๋™์ผ ์ €์ž์—ฌ๋„ ์ถœํŒ์‚ฌ๊ฐ€ ๋‹ค๋ฅผ์ˆ˜ ์žˆ๋‹ค. ํ•จ๊ป˜ ์ € ์žฅํ–ˆ์„ ๊ฒฝ์šฐ ์ฐจ ํ›„ SQL๋ฌธ์ด ๋ณต์žกํ•ด์ง€๊ณ , ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ ๊ฒฐ์—ฌ ์œ„ ํ—˜, ์†์„ฑ์— ์ œ์•ฝ์„ ๊ฑธ๊ธฐ๊ฐ€ ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์— ์ •๊ทœํ™” ๊ณผ์ •์„ ๋ถ„๋ฆฌํ•˜ ์—ฌ ์ €์žฅํ•˜๋Š”๊ฒŒ ๋ฐ”๋žŒ์งํ•˜๋ฉฐ ํ•˜๋‚˜์˜ ํ•„๋“œ์— ํ†ตํ•ฉํ•˜์—ฌ ์ €์žฅํ•˜์—ฌ๋„ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ๊ณต๊ฐ„์ด ์ถฉ๋ถ„ํ•˜๊ณ , ๋นˆ๋ฒˆํ•˜๊ฒŒ ๋‘˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ•จ๊ป˜ ์กฐํšŒ ํ•˜๋Š”๊ฒฝ์šฐ ์œ„์™€๊ฐ™์€ ๋ฆฌ์Šคํฌ๋ฅผ ๊ฐ์†Œํ•œ๋‹ค๋ฉด ๊ฐ€๋Šฅํ•˜๋‹ค.
  1. ์œ„์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ดํŽด๋ณด๋ฉด ๊ฐ™์€ ์ฑ…, ํ˜น์€ ๊ฐ๊ฐ์˜ ์ฑ…์— ๋Œ€ ํ•ด ๋นŒ๋ ค๊ฐ„ ์ง€์ ๊ณผ ์‚ฌ๋žŒ๊ณผ ๋Œ€์ถœ, ๋ฐ˜๋‚ฉ์ผ์ž๋“ฑ์ด ๋‹ค๋ฅด๊ณ  BOOK_LOANS์ด ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ์†์„ฑ์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋งŽ๊ธฐ ๋•Œ๋ฌธ์— ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ”๋กœ ์ €์žฅํ•˜๋Š”๊ฒƒ ๋ณด๋‹ค ๋”ฐ๋กœ ์ •๋ณด๋ฅผ ๋‚˜๋ˆ„์„œ ์ •๊ทœํ™” ๊ณผ ์ •์„ ๊ฑฐ์ฒ˜ ๊ด€๋ฆฌํ•˜๋Š”๊ฒƒ์ด ๋ฐ์ดํ„ฐ์˜ ๋ฌด๊ฒฐ์„ฑ๊ณผ ๊ด€๋ฆฌ์  ์ธก๋ฉด์—์„œ ํšจ ์œจ์ ์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

  • ์ฐธ์กฐํ•˜๋Š” ํ…Œ์ด๋ธ”์—์„œ ์™ธ๋ž˜ ํ‚ค ์ œ์•ฝ ์กฐ๊ฑด ์„ค์ • ์‹œ ON DELETE CASCADE ์˜ต์…˜์„ ์‚ฌ์šฉํ•ด์•ผ ์ฐธ์กฐ ๋ฌด๊ฒฐ์„ฑ์ด ์ง€์ผœ์ง„๋‹ค.
SELECT A.DNAME, COUNT(B.DNUMBER) FROM DEPARTMENT A, DEPT_LOCATIONS B WHERE A.DNUMBER = B.DNUMBER GROUP BY A.DNAME, B.DNUMBER; -- ๋‘˜์ด ๊ฐ™์Œ SELECT A.DNAME, COUNT(B.DNUMBER) FROM DEPARTMENT A INNER JOIN DEPT_LOCATIONS B ON A.DNUMBER = B.DNUMBER GROUP BY A.DNAME, B.DNUMBER;
  • SQL์—์„œ GROUP BY๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, SELECT ์ ˆ์— ์žˆ๋Š” ๋ชจ๋“  ํ•„๋“œ๋Š” GROUP BY ์ ˆ์— ํฌํ•จ๋˜์–ด์•ผ ํ•œ๋‹ค. ์ฆ‰, ์ง‘๊ณ„ ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ํ•„๋“œ๋“ค์€ ๋ชจ๋‘ ํฌํ•จ๋˜์–ด์•ผ ํ•œ๋‹ค.
  • WHERE์ ˆ์€ ํ…Œ์ด๋ธ”์— ์žˆ๋Š” ํ–‰๋“ค์— ๋Œ€ํ•œ ์กฐ๊ฑด (๊ทธ๋ฃนํ™”๋˜๊ธฐ ์ „), HAVING ์ ˆ์€ ๊ทธ๋ฃนํ™”๋œ ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ ์กฐ๊ฑด์„ ์„ค์ •
  • ์ค‘์ฒฉ ์งˆ์˜์—์„œ ์™ธ๋ถ€ ์งˆ์˜์— ํฌํ•จ๋œ ํ…Œ์ด๋ธ”์˜ ์†์„ฑ์„ ๋‚ด๋ถ€ ์งˆ์˜์—์„œ ์ฐธ์กฐํ•˜๋Š” ๊ฒฝ์šฐ ๋‚ด๋ถ€ ์งˆ์˜ ์‹คํ–‰ํšŸ์ˆ˜๋Š” ์™ธ๋ถ€ ์งˆ์ด์˜ ํŠœํ”Œ ์ˆ˜ ๋งŒํผ ์‹คํ–‰๋œ๋‹ค.

  • ๋ฐ์ดํ„ฐ ๋…๋ฆฝ์„ฑ์ด ์ œ๊ณต๋˜์ง€ ์•Š์œผ๋ฉด ๋ฌผ๋ฆฌ์  ์ €์žฅ ๊ตฌ์กฐ๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ๋งˆ๋‹ค ์‘์šฉ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์˜ํ–ฅ์„ ๋ฐ›์•„ ์ˆ˜์ •์ด ํ•„์š”ํ•˜๊ฒŒ ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์˜ ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ค์›Œ์ง„๋‹ค.
1. SELECT ์ด๋ฆ„, ๊ณผ๋ชฉ๋ช… FROM STUDENT INNER JOIN (COURSE INNER JOIN ์ˆ˜๊ฐ•์‹ ์ฒญ ON COURSE.์ฝ”์Šค๋ฒˆํ˜ธ = ์ˆ˜๊ฐ•์‹ ์ฒญ.์ฝ”์Šค๋ฒˆํ˜ธ) ON STUDENT.ํ•™๋ฒˆ = ์ˆ˜๊ฐ•์‹ ์ฒญ.ํ•™๋ฒˆ 2. SELECT STUDENT.์ด๋ฆ„, COUNT (*), AVG(์„ฑ์ ) FROM STUDENT INNER JOIN ์ˆ˜๊ฐ•์‹ ์ฒญ ON STUDENT.ํ•™๋ฒˆ = ์ˆ˜๊ฐ•์‹ ์ฒญ.ํ•™๋ฒˆ GROUP BY STUDENT.์ด๋ฆ„; 3. SELECT COURSE.๊ณผ๋ชฉ๋ช…, COUNT (*), AVG(์„ฑ์ ) FROM STUDENT INNER JOIN (COURSE INNER JOIN ์ˆ˜๊ฐ•์‹ ์ฒญ ON COURSE.์ฝ”์Šค๋ฒˆํ˜ธ = ์ˆ˜๊ฐ•์‹ ์ฒญ.์ฝ”์Šค๋ฒˆํ˜ธ) ON STUDENT.ํ•™๋ฒˆ = ์ˆ˜๊ฐ•์‹ ์ฒญ.ํ•™๋ฒˆ GROUP BY COURSE.๊ณผ๋ชฉ๋ช…; SELECT COURSE.์ฝ”์Šค๋ฒˆํ˜ธ, COURSE.๊ณผ๋ชฉ๋ช…, COUNT(์ˆ˜๊ฐ•์‹ ์ฒญ.ํ•™๋ฒˆ), AVG(์ˆ˜๊ฐ•์‹ ์ฒญ.์„ฑ์ ) FROM COURSE INNER JOIN ์ˆ˜๊ฐ•์‹ ์ฒญ ON COURSE.์ฝ”์Šค๋ฒˆํ˜ธ = ์ˆ˜๊ฐ•์‹ ์ฒญ.์ฝ”์Šค๋ฒˆํ˜ธ GROUP BY COURSE.์ฝ”์Šค๋ฒˆํ˜ธ, COURSE.๊ณผ๋ชฉ๋ช…; 4. SELECT ํ•™๊ณผ.ํ•™๊ณผ๋ช…, COUNT (*) FROM ํ•™๊ณผ INNER JOIN COURSE ON ํ•™๊ณผ.ํ•™๊ณผ๋ฒˆํ˜ธ = COURSE.ํ•™๊ณผ์ •๋ณด GROUP BY ํ•™๊ณผ.ํ•™๊ณผ๋ช… HAVING COUNT (*) >= 3; 5. SELECT ๊ณผ๋ชฉ๋ช…, ํ•™์  FROM COURSE WHERE ์ฝ”์Šค๋ฒˆํ˜ธ IN (SELECT ์ˆ˜๊ฐ•์‹ ์ฒญ.์ฝ”์Šค๋ฒˆํ˜ธ FROM ์ˆ˜๊ฐ•์‹ ์ฒญ WHERE ํ•™๊ธฐ LIKE "2013-2"); 6. SELECT ๊ณผ๋ชฉ๋ช… FROM COURSE WHERE (SELECT COUNT (*) FROM ์ˆ˜๊ฐ•์‹ ์ฒญ WHERE COURSE.์ฝ”์Šค๋ฒˆํ˜ธ = ์ˆ˜๊ฐ•์‹ ์ฒญ.์ฝ”์Šค๋ฒˆํ˜ธ) >= 2;
ย 

๋Œ“๊ธ€

guest