October 29, 2008 at 6:32 am
Hi,
I'm have some queries that look on two table with a join. All the fields in the join are indexed as well as the fields that are queried. I was wondering if there are any advantage to create a view with same join and then index that view? I mean, is it basiclally the same thing or internally, SQL Server does some magic that makes views faster?
Thanks,
Stephane
October 29, 2008 at 6:37 am
From BOL:
A view is a virtual table whose contents are defined by a query. Like a real table, a view consists of a set of named columns and rows of data. Unless indexed, a view does not exist as a stored set of data values in a database. The rows and columns of data come from tables referenced in the query defining the view and are produced dynamically when the view is referenced
So unless you have an indexed view it likely will not perform better than a query that duplicates it. In my experience views are used to encapsulate common queries to save time when coding and also for security purposes. I rarely grant direct table access to anyone, but use stored procedures and views to help protect the data.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
October 29, 2008 at 6:41 am
thanks!
That's what I thought... So it seems useless to create a view and to index it on the same fields that are already indexed?
Stephane
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply