연구개발/SQL2005
INDEXING VIEW
HEAD1TON
2010. 6. 18. 01:26
/* 1.View는 원본의 select구문을 실행시키주는 역할로서
서버 자체 속도 향상의 효과는 없다.
2.View 실행시 원본 table에 접근하여 결과 값을 찾는 행동을
index화 시켜 줌으로서 쿼리문의 속도향상을 꾀 할 수있다.
3.하지만, 원본 table의 값이 바뀌면 indexing view도 값을 바꿔
줘야 하기 때문에, 보통의 index가 가지고 있는 단점인 서버부하
가 빈번히 일어나게 된다.
그러므로, 값이 자주 바뀌는 동적인 table보다는 정적인 table에
서 생성하는게 좋다.
*/
ex)
select * from sawon
select * from dept
sp_helpconstraint dept
sp_helpconstraint sawon
create view a_money with schemabinding
as
select count_big(*) '부서인원'
,d.deptno
,sum(isnull(s.sal,0)*12+isnull(s.comm,0)) 'yearpay'
from dbo.sawon s inner join dbo.dept d
on s.deptno = d.deptno
group by d.deptno
create unique clustered index a_u_clidx_a_money_deptno
on a_money(deptno);
select * from a_money