|Lesson 2||What is a view? |
|Objective|| Understand what an SQL View is.|
What is View in SQL ?
Views are like windows to the data in your system. If you think of a view like a window to the outside world, the window always gives
you the same relative look at things, but also shows changes that pass in front of it. Views are stored queries that you can call on later to retrieve information from the tables.
The SlideShow shows this idea graphically.
- Columns for a table named MyTable
- You can think of a view as a window into the database.
- In one particular instance, you might use the view (i.e., look through the window) and see the customer name Jane Doe
- The next time you use the same view, (look through the same window) you may see different data.
SQL View Defined.
A view starts as a SELECT statement, with all the capabilities that you have come to know from SELECT.
You can also think of a view as a query that is remembered by the engine.
The really neat thing about views is that you can refer to them as tables. For example, suppose you have the following table:
You can create a view of the table that includes only those customers with a state of "UT".
As usual, to create a basic SQL statement that does this, you would use the following:
SELECT * FROM CustomerTable
WHERE State = 'UT'
Once you have this query, it would be nice to refer to it by name, retrieving the values from the query without having to write the whole SQL statement over again?
That is where views come in.
In Access, views are equivalent to queries.
Queries can be saved, and queries can be the target of SELECT statements in other queries. You may have to determine the specific name used by your engine if it supports views.
In some engines, you will hear views called stored queries, saved queries, or virtual views.