Tuesday, March 6, 2012

"Difference"

Hai,
I want to know what is the difference between views and joins. why we are going for views in sql server.

JOIN is a method of accessing data from few tables in one query.

View is a "saved" SELECT query, you could use view as a table in other queries.

|||

In addition to the explanation already offered ...

A View is typically used by people who are not familiar with details of various tables in a database or how they should be joined (such as people in an end-user department).

You must remember, however, that the convenience of a View comes with a performance cost. As a result, some organizations have a tentency to discourage usage of Views (or use them on a limited basis only).

Ben

|||

I don't think I would put it the same way. As far as I know, there is usually no inherent performance cost associated with a view. However, keep in mind that a view is in fact a tool. And unfortunately tools are only as good as the person using the tool.

There is a lot of truth in that of end users who use views without much thought and will build reports based on multiple views or even create views that contain other views. The problem with this is that frequently such an approach is done without looking at the details of the components of a view. And THIS can lead to performance problems.

Frequently under such circumstance one or multiple component tables of the view can be unused by a query. When this happens the end user is now processing a lot of "spectator data" -- and spectator data is pure overhead. Here the problem is that views are created to create a simpler looking facade while hiding the details of what is actually going on.

It is frequently simpler for a user to use the simple-looking facade of a view and join that with other objects -- especially other views that leads to problems.

Oh, yes, one more thing: I also sometimes cringe when report writers get a little too-interested in views.

|||

I typically use views when I have to write or have the possibility to write the same query multiple times in my application(s) and the benefits of having that view in one place and not writing lengthy SQL in my app pays off. It also provides a layer of isolation, so that if the underlying sources of data changes, I do not have to change my application and can 'mask' the changes in the view.

|||

Agreed.

View is a well-intended tool -- and almost a necessity in the array of tools we use within the database technology.

Nonetheless, it can be easily missused as well.

Can you imagine how many meetings I have been to where someone mentioned "View" and all of a sudden eyebrowes are raised and "not again" is heard?!

This may be an unfortunate reality, but we cannot deny that it exists.

Ben

No comments:

Post a Comment