Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL 2005 How do you create a Index Over a View

Posted on 2010-09-08
7
Medium Priority
?
340 Views
Last Modified: 2012-05-10
I can create a View in SQL 2005 by Choosing Views and then create a view.
Now if I want to create a index over that view where do I do that ?
Within my stored procedure ?
I don't want to recreate my view index everytime that stored procedure is called ?
And where is that view index stored in SQL 2005 ?
Looks like creating a index over a view is not as simplified as creating a index over a table.
0
Comment
Question by:thayduck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:Marbleman
ID: 33631183
As the name "view" states, your are just "viewing" data with it and not storing this selection somewhere.

Therefor you cannot add an index to a a view. I cannot think of a situation that would make this necessary...

However you could do something like that with "SELECT INTO newTable..." but this duplicates the data.
0
 
LVL 5

Accepted Solution

by:
David Christal CISSP earned 168 total points
ID: 33631242
You are correct, indexed views are not as simple as indexed tables.  Here is an article describing the ins and outs of creating indexes on views.  

http://technet.microsoft.com/en-us/library/cc917715.aspx#XSLTsection124121120120

Generally, they are not needed if the related tables are well indexed.  Per the article: "Frequently occurring aggregations and joins are the best candidates for indexed views."
0
 

Author Comment

by:thayduck
ID: 33631257
This IBM site talks about Indexed Views. Thats what got me thinking.

 http://technet.microsoft.com/en-us/library/cc917715.aspx
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:mustaccio
ID: 33631273
There are some limitations as to what views can be indexed, but generally you indeed can create indexes over views. That essentially materializes the view results.

You create an index for a view with a regular CREATE VIEW statement. The first index must be unique and clustered.

You will find more details here: http://technet.microsoft.com/en-us/library/cc917715.aspx
0
 

Author Comment

by:thayduck
ID: 33631347
Sorry dchristal, sent answer before I read your response.
We saw same thing.

I have created 3 indexes over the table that I then created a view over.

I created the view because there are approx 8 flds in the table that could contain a $ amt and if they do then I include record into the report. If all flds are 0 then I ignore the record. I thought it would be better to create a view and only include records that have a $ amt in 1 of these 8 flds. But after I did that I realized I probably lost my index's  since they are over the table and not the view. Thats what made me curious about View Index's..

Will probably re think and put a better Where clause in my query.. and forget about the View..
0
 
LVL 25

Assisted Solution

by:DBAduck - Ben Miller
DBAduck - Ben Miller earned 168 total points
ID: 33631412
When you use a View you don't lose the indexes.  A view is meta-data and still knows about the views.  The only time you lose the power of indexes is if you use a (SELECT query) inside a select query, which creates a Virtual Table.  Then you lose the indexes.

So you should not forget about the view, it should be just fine to use it.  But you could materialize the view with SCHEMABINDING to make it into a psuedo table and only have those columns in the table.  Sometimes this is useful when you have a lot of columns in the table and you don't want to scan or go after the base table.
0
 
LVL 22

Assisted Solution

by:8080_Diver
8080_Diver earned 164 total points
ID: 33631816
Something to bear in mind, though, is that an Indexed View is, indeed, instantiated and changes to the underlying table will result in the recreation of that view.  If you have a lot of INSERTS, UPDATES, or DELETES impacting the underlying table, you can be adding a good bit more load on the database because each of them will trigger the INDEXED VIEW rebuild.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question