๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

์˜ค๋ผํด3

[DB] ์ •๊ทœํ™” ์ค‘๋ณต์„ ์ตœ์†Œํ™”ํ•˜๊ธฐ์œ„ํ•ด์„œ ์ •๊ทœํ™”๋ฅผ ํ•œ๋‹ค. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๊ฐ€์žฅ ํฐ ๋ชฉ์ ์€ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์™œ? ์ค‘๋ณต์ด ์žˆ์œผ๋ฉด ์ด์ƒ ํ˜„์ƒ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ๐ŸŽฒ ์ด์ƒ ํ˜„์ƒ ( Anomaly ) ์‚ญ์ œ์ด์ƒ: ์—ฐ์‡„์  ์‚ญ์ œ ๋ฌธ์ œ ๋ฐœ์ƒ ์‚ฝ์ž…์ด์ƒ: NULL ๊ฐ’ ๋ฌธ์ œ ๋ฐœ์ƒ ์ˆ˜์ •์ด์ƒ: ๋ถˆ์ผ์น˜ ๋ฌธ์ œ ๋ฐœ์ƒ ๐ŸŽฒ ํ•จ์ˆ˜ ์ข…์†์„ฑ( Functional Dependency ) ์–ด๋–ค ์†์„ฑ์˜ ๊ฐ’์„ ์•Œ๋ฉด ๋‹ค๋ฅธ ์†์„ฑ ๊ฐ’์ด ์œ ์ผํ•˜๊ฒŒ ์ •ํ•ด์ง€๋Š” ์˜์กด ๊ด€๊ณ„๋ฅผ ์ข…์†ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ex. ํ•™์ƒ ๋ฒˆํ˜ธ๋ฅผ ์•Œ๋ฉด ํ•™์ƒ์ด๋ฆ„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ํ•™์ƒ๋ฒˆํ˜ธ๋กœ ํ•™์ƒ์ด ์ˆ˜๊ฐ•ํ•˜๋Š” ๊ฐ•์ขŒ์ด๋ฆ„์„ ์œ ์ผํ•˜๊ฒŒ ์•Œ ์ˆ˜๋Š” ์—†๋‹ค. (์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ˆ˜๊ฐ•ํ•  ์ˆ˜ ๋„ ์žˆ๊ธฐ๋•Œ๋ฌธ์—) X ๊ฐ๊ฐ์˜ ๊ฐ’์ด Y์˜ ๊ฐ’ ํ•œ ๊ฐœ์™€ ๋Œ€์‘์ด ๋˜๋ฉด ‘X๋Š” Y๋ฅผ ํ•จ์ˆ˜์ ์œผ๋กœ ๊ฒฐ์ •ํ•œ๋‹ค’, X→Y๋กœ ํ‘œ๊ธฐํ•œ๋‹ค. X๊ฐ€ ๊ฒฐ์ •์ž์ด๋‹ค. * ํ•จ์ˆ˜ .. 2024. 1. 2.
[DB] ๋ถ€์† ์งˆ์˜(sub query) ์—ฐ์Šต๋ฌธ์ œ 1. ๋งˆ๋‹น์„œ์ ์˜ ๊ณ ๊ฐ์ด ์š”๊ตฌํ•˜๋Š” ๋‹ค์Œ ์งˆ๋ฌธ์— ๋Œ€ํ•ด SQL ๋ฌธ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. (5) ๋ฐ•์ง€์„ฑ์ด ๊ตฌ๋งคํ•œ ๋„์„œ์˜ ์ถœํŒ์‚ฌ ์ˆ˜ (6) ๋ฐ•์ง€์„ฑ์ด ๊ตฌ๋งคํ•œ ๋„์„œ์˜ ์ด๋ฆ„, ๊ฐ€๊ฒฉ, ์ •๊ฐ€์™€ ํŒ๋งค๊ฐ€๊ฒฉ์˜ ์ฐจ์ด (7) ๋ฐ•์ง€์„ฑ์ด ๊ตฌ๋งคํ•˜์ง€ ์•Š์€ ๋„์„œ์˜ ์ด๋ฆ„ -- 5. SELECT PUBLISHER FROM BOOK WHERE BOOKID IN (SELECT BOOKID FROM ORDERS WHERE CUSTID=1); -- 6. SELECT CS.NAME, BK.BOOKNAME, BK.PRICE, BK.PRICE - OD.SALEPRICE "์ฐจ์ด" FROM CUSTOMER CS, ORDERS OD, BOOK BK WHERE CS.CUSTID = OD.CUSTID AND OD.BOOKID = BK.BOOKID AND CS.CUSTID.. 2023. 12. 29.
[DB] DML ์—ฐ์Šต๋ฌธ์ œ ๐ŸŒž ์˜ค๋ผํด๋กœ ๋ฐฐ์šฐ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ฐœ๋ก ๊ณผ ์‹ค์Šต ์—ฐ์Šต๋ฌธ์ œ 1 ๋งˆ๋‹น์„œ์ ์˜ ๊ณ ๊ฐ์ด ์š”๊ตฌํ•˜๋Š” ๋‹ค์Œ ์งˆ๋ฌธ์— ๋Œ€ํ•ด SQL ๋ฌธ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. (1) ๋„์„œ๋ฒˆํ˜ธ๊ฐ€ 1์ธ ๋„์„œ์˜ ์ด๋ฆ„ (2) ๊ฐ€๊ฒฉ์ด 20,000์› ์ด์ƒ์ธ ๋„์„œ์˜ ์ด๋ฆ„ (3) ๋ฐ•์ง€์„ฑ์˜ ์ด ๊ตฌ๋งค์•ก(๋ฐ•์ง€์„ฑ์˜ ๊ณ ๊ฐ๋ฒˆํ˜ธ๋Š” 1๋ฒˆ์œผ๋กœ ๋†“๊ณ  ์ž‘์„ฑ) (4) ๋ฐ•์ง€์„ฑ์ด ๊ตฌ๋งคํ•œ ๋„์„œ์˜ ์ˆ˜(๋ฐ•์ง€์„ฑ์˜ ๊ณ ๊ฐ๋ฒˆํ˜ธ๋Š” 1๋ฒˆ์œผ๋กœ ๋†“๊ณ  ์ž‘์„ฑ) SELECT BOOKNAME FROM BOOK WHERE BOOKID = 1; SELECT BOOKNAME FROM BOOK WHERE PRICE >= 20000; SELECT SUM(SALEPRICE) FROM ORDERS WHERE CUSTID = 1; SELECT COUNT(*) FROM ORDERS WHERE CUSTID =1; 2 ๋งˆ๋‹น์„œ์ ์˜ ์šด์˜์ž.. 2023. 12. 28.
728x90