MapleStory Finger Point

๐Ÿ’Ž DataBase/๐Ÿ’Ž SQL-PL,SQL

[SQL] VIEW ๋ทฐ

HYEJU01 2024. 6. 20. 02:42


[๊ฐœ๋…]

๋ฐ์ดํ„ฐ ๊ด€๋ฆฌ์šฉ object ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

๊ฐ€์ƒํ…Œ์ด๋ธ”์„ ์˜๋ฏธํ•˜๋ฉฐ, View ์—๋Š” ๋ฐ์ดํ„ฐ๋Š” ์—†๊ณ  ์›๋ณธ ํ…Œ์ด๋ธ”์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” SQL Query ๋งŒ ๋‹ด๊ฒจ์žˆ๋‹ค.

๋ณด์•ˆ๊ณผ ์‚ฌ์šฉ์ž ํŽธ์˜์„ฑ์„ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

 


[๋‹จ์ˆœ๋ทฐ Simple View]  

view ๋ฅผ ์ƒ์„ฑํ•  ์„œ๋ธŒ์ฟผ๋ฆฌ์— ์กฐ์ธ์กฐ๊ฑด์ด ์•ˆ๋“ค์–ด๊ฐ€๊ณ 

1๊ฐœ์˜ ํ…Œ์ด๋ธ”๋กœ๋งŒ ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฐ„๋‹จํ•œ view

CREATE OR REPLACE VIEW v_emp1
AS
SELECT empno, ename, hiredate
FROM emp;


[๋ณตํ•ฉ๋ทฐ Complex View]

์„œ๋ธŒ์ฟผ๋ฆฌ ๋ถ€๋ถ„์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ…Œ์ด๋ธ”์ด ์กฐ์ธ ๋˜์–ด ์ƒ์„ฑ๋˜๋Š” ๊ฒƒ

(์ง‘ํ•ฉ์—ฐ์‚ฐ์ž๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„์•ผ ์„ฑ๋Šฅ ํ–ฅ์ƒ์— ๋„์›€ ๋จ)

CREATE OR REPLACE VIEW v_emp1
AS
SELECT empno, ename, hiredate
FROM emp;

SELECT * FROM v_emp; -- ๋ทฐ์˜ ์„œ๋ธŒ์ฟผ๋ฆฌ ๋ถ€๋ถ„ ์‹คํ–‰๋จ

 

 


[์ธ๋ผ์ธ๋ทฐ Inline View]

๋‹ค๋ฅธ ์ฟผ๋ฆฌ์—์„œ ์‚ฌ์šฉ ํ•  ํ•„์š” ์—†์ด, ํ•ด๋‹น SQL ์—์„œ๋งŒ ํ•„์š”ํ•œ view ๋Š” ์ธ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

SELECT e.deptno, d.dname, e.sal
FROM (SELECT deptno, MAX(sal), sal
	FROM emp
    GROUP BY deptno) e, dept d
WHERE e.deptno = d.deptno;

 


[๋ทฐ ์กฐํšŒ ๋ฐ ์‚ญ์ œ]

drop view v_emp;


[Materialized View ๊ตฌ์ฒดํ™”๋œ ๋ทฐ]

 

[Mview]