Difference between view an join?

  • 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

  • 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.

  • 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