Thursday, June 12, 2014

INDEXED VIEWS

A view whose query result is stored in database is called indexed view.

Index view are created mainly for two reasons
To improve performance of aggregate operations
To create a local copy for remote database

View
Indexed view
When view is created, the query is stored in database
When indexed view is created  , the query result is stored in database
A view does not contain any data
Index view contains data


Follow steps while creating index view.

Create a view with schema binding
Create index on that view

create view indv1 with schemabinding
as
select deptno,SUM(isnull(sal,0)) sumsal, COUNT_BIG(*) emps from dbo.EMP group by DEPTNO

step2:
create unique clustered index on group by column that is deptno.
create unique clustered index ind1  on indv1(deptno)


select *from indv1

update EMP setSAL=SAL+1000 where DEPTNO=10


after creating indexed view, if we make any changes to base table the changes are reflected to index view automatically

No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...