View

[MySQL] View์ƒ์„ฑ ๋ฐ ์‚ญ์ œ

์ฑ…์ฝ๋Š” ๊ฐ์ž 2022. 9. 14. 14:28
๋ฐ˜์‘ํ˜•

๐Ÿ’ก VEIW ์ƒ์„ฑ

  • ๋‹จ์ผ ํ…Œ์ด๋ธ” , ๋‹ค์ค‘ ํ…Œ์ด๋ธ”: ์กฐ์ธ, ์„œ๋ธŒ์ฟผ๋ฆฌ, ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” Read Only ๋“ฑ → ๋น„์šฉ ์ ˆ๊ฐ์„ ์œ„ํ•จ
#viwe ์ƒ์„ฑ: create view [Or replace ] view ์ด๋ฆ„ as select query;
create view v_employee
as
select e.employee_id as '์‚ฌ์›๋ฒˆํ˜ธ', e.first_name as '์‚ฌ์›๋ช…', d.department_name '๋ถ€์„œ๋ช…'
from employees e, departments d
where e.department_id = d.department_id;
#๋‚˜์ค‘์— rollback์„ ์œ„ํ•ด ์„ธํŒ… 
set autocommit=false;

#๋ทฐ ์ƒ์„ฑ ํ›„ ํ™•์ธ
select * from v_employee;

#์ฐธ์กฐ ํ…Œ์ด๋ธ” ๋ณ€๊ฒฝ1
select department_id
from employees
where employee_id=202;

update employees
set department_id=10
where employee_id=202;

#๋ทฐ ํ™•์ธ
select * from v_employee;

#์ฐธ์กฐ ํ…Œ์ด๋ธ” ๋ณ€๊ฒฝ2
update employees
set department_id=10
where employee_id=202;

update departments
set department_name ='๊ด€๋ฆฌ๋ถ€'
where department_id=10;

๊ธฐ์กด์˜ ํ…Œ์ด๋ธ”(์ฐธ์กฐ๋œ ํ…Œ์ด๋ธ”)์—๋„ ๋ฌผ๋ฆฌ์ ์ธ ๋ณ€๊ฒฝ์ด ์žˆ์„ ์‹œ์—๋„ ๋ทฐ์—๋„ ๋ฐ˜์˜์ด ๋˜๋Š”๊ฐ€?

ใ…‡ใ…‡, ๋ฐ˜์˜์ด ๋œ๋‹ค

 

๐Ÿ’ก VEIW ์‚ญ์ œ

#๋ทฐ ์‚ญ์ œ DROP view ์ด๋ฆ„ 
DROP view v_employee;

๋ทฐ ์‚ญ์ œ์™€ ์ฐธ์กฐ๋œ ํ…Œ์ด๋ธ”์€ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค

๋ฐ˜์‘ํ˜•
Share Link
reply
๋ฐ˜์‘ํ˜•
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30