Search code examples
sql-serversql-server-2008indexed-view

Sql server indexed view


OK, I'm confused about sql server indexed views(using 2008)

I've got an indexed view called

AssignmentDetail

when I look at the execution plan for

select * from AssignmentDetail

it shows the execution plan of all the underlying indexes of all the other tables that the indexed view is supposed to abstract away.

I would think that the execution plan woul simply be an clustered index scan of PK_AssignmentDetail(the name of the clustered index for my view) but it doesn't.

There seems to be no performance gain with this indexed view what am I supposed to do? Should I also create a non-clustered index with all of the columns so that it doesn't have to hit all the other indexes?

Any insight would be greatly appreciated


Solution

  • The Enterprise edition of SQL Server is smart enough to look for and make use of indexed views when they exist. However, if you are not running Enterprise edition, you'll need to explicitly tell it to use the indexed view, like this:

    select * 
    from AssignmentDetail WITH (NOEXPAND)