#title View [[TableOfContents]] ==== View란? ==== '뷰테이블'이 아니고 그냥 '뷰'다. 이그.. ==== Indexed View 의 제약사항(2005) ==== * SCHEMABINDING 옵션을 사용해야 한다. * 기술된 테이블은 모두 [스키마].[테이블명]과 같이 2Part 명칭을 사용해야 한다. * COUNT_BIG() 함수가 포함되어야 한다. * Unique Clustered Index를 생성해야 한다. * view 정의에 top(100 percent) ~ order by 를 포함시켰어도 view를 사용할 때는 정렬을 보장하지 않는다. 게시판에 이용? SELECT ROW_NUMBER() OVER(...) RowNum FROM 테이블 WHERE RowNum BETWEEN 1 and 10 ==== 저장프로시저를 테이블처럼 이용하는 방법 ==== 1. 먼저 Loopback 링크드 서버를 만든다. 2. SELECT * FROM OPENQUERY (Loopback, 'Exec myDB..') 과 같이 이용한다. 3. 또 다른 방법으로 2번 결과를 View로 만든다. ==== 참고자료 ==== * [http://www.sqlservercentral.com/articles/Performance/71482/ Indexed Views] * [http://technet.microsoft.com/en-us/library/dd171921.aspx Improving Performance with SQL Server 2008 Indexed Views] ==== 분할 뷰 예제 ==== {{{ --테이블 create table dbo.em_log_201309 ( tran_date datetime , val int ) create table dbo.em_log_201310 ( tran_date datetime , val int ) go create clustered index cix_tran_date on dbo.em_log_201309(tran_date) create clustered index cix_tran_date on dbo.em_log_201310(tran_date) go create view v_em_log as select tran_date, val from dbo.em_log_201309 where tran_date between '20130901' and '20130930' union all select tran_date, val from dbo.em_log_201310 where tran_date between '20131001' and '20131031' go --날짜 조건을 줘야 원하는 테이블에서만 데이터를 쪽 뽑음 select * from dbo.v_em_log where 1=1 and tran_date >= '20131011' and tran_date < '20131012' }}}