Reputation: 1935
I'm not a SQL programmer, however my instructor has asked us how a "View" could have helped us return relevant data on a recent project from four different tables as opposed to using Joins to join the 4 tables. My understanding is that I would still have to Join the tables. I cannot think of any other way that a View could help in this regard.
Am I correct in assuming that even creating a View, I am still going to have to join the tables?
Am I being given a sub-par education in SQL?
Upvotes: 0
Views: 109
Reputation:
A view is just a saved query. Views can be helpful for allowing not technical users the ability to simply query the view rather than developing their own ad hoc query (which may be incorrect). This is similar to the concept of a data warehouse but obviously much different from an implementation, maintenance, functionality, and performance perspective.
As you mentioned your a student i'll explain further. If you want to query the database for an answer to a question that hasn't been answered before, and likely will not be asked again in the same way, you can just write an ad hoc query. These queries a likely to be short and simple. If you constantly query the same thing over and over again, you can create a view and simply query the view. So if a view is just a saved query, than what is a stored procedure and how is it different. Well I'm glad you asked. A stored procedure is a set of SQL statements that are precompiled by SQL server. They are typically long and relatively complex. Also, whereas in a view you are simply selecting data, in a stored procedure you would be manipulating data.
I know my answer goes a little out of the bounds of your professors question, but I hope it gets the wheels turning for you and gives you some topics to start researching for later in your academic or professional career :)
Upvotes: 1
Reputation: 111
The benefit of a view is that you can abstract away the JOINs in queries that utilize the view, rather than having to include a JOIN in every query - the view just saves those JOINs for cleaner code
So yes, you'll still write JOINs, but you'll write them once instead of every time.
Upvotes: 2