๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[๊ฐœ๋ฐœ] Practice/SQL Database

[SQL / Database] Table ๋Œ€์‹  View ์‚ฌ์šฉํ•ด๋ณด๊ธฐ

by Connecting-the-dots 2023. 6. 4.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’กTable ๋Œ€์‹  View ์‚ฌ์šฉํ•ด๋ณด๊ธฐ

๐Ÿ’œ View ์•Œ์•„๋ณด๊ธฐ

CREATE VIEW ๋ทฐ๋ช… AS SELECT ์ปฌ๋Ÿผ1, ์ปฌ๋Ÿผ2, ... FROM ํ…Œ์ด๋ธ”๋ช…
  • SELECT ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ํ…Œ์ด๋ธ”๋กœ ๋‘๊ณ ๋‘๊ณ  ์ €์žฅํ•ด์„œ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ Table ๋Œ€์‹   View ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • View ๋Š” ๊ฐ€์ƒ ํ…Œ์ด๋ธ”์ฒ˜๋Ÿผ SELECT ๋ฌธ์„ ํ…Œ์ด๋ธ” ํ˜•ํƒœ๋กœ ๋ณด์—ฌ์ฃผ๋ฉฐ, ํ…Œ์ด๋ธ”๊ณผ ๋™์ผํ•˜๊ฒŒ SELECT, INSERT, UPDATE, DELETE ๋ชจ๋‘ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
    (์ผ๋ถ€ DBMS ๋Š” SELECT ๋ฌธ๋ฒ•๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•  ์ˆ˜๋„ ์žˆ๋‹ค.)
  • SELECT ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฐพ์€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  View ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฌธ๋ฒ•์€ ์œ„์™€ ๊ฐ™๋‹ค.
  • ์ฃผ๋กœ JOIN ํ•ด์„œ ์ž‘์„ฑํ•ด๋’€๋˜ SELECT ๋ฌธ์„ ํ…Œ์ด๋ธ”ํ˜•ํƒœ๋กœ ์žฌ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์žฅ์ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
    • ๋ณต์žกํ•˜๊ฒŒ JOIN ํ•ด๋‘” ํ…Œ์ด๋ธ”๋“ค์„ ์‰ฝ๊ฒŒ ์žฌ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ์–ด ํŽธ๋ฆฌํ•˜๋‹ค.
    • ์‹ค์ œ ํ…Œ์ด๋ธ”์ด ์•„๋‹ˆ๋ฏ€๋กœ ํ…Œ์ด๋ธ”๋งŒํผ ํ•˜๋“œ์šฉ๋Ÿ‰์„ ๋งŽ์ด ์ฐจ์ง€ํ•˜์ง€ ์•Š๋Š”๋‹ค.
    • table ์— ์ปฌ๋Ÿผ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•  ๋•Œ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด์„œ ํ…Œ์ŠคํŠธํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.
    • View ์•ˆ์—์„œ ๋˜ SELECT ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ค‘์ฒฉ๋œ View ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
728x90
๋ฐ˜์‘ํ˜•