Views are virtual tables. They do not contain any data themselves -
rather they're a structure to allow us to access data, or a subset
of the data. A view can consist of a subset of one table, such
as in this example:
Poet
- Code
- First name
- Surname
- Age
- Address
- Telephone
This is the complete list of fields from the poet table
Subscriber view
- Code
- First_name
- Surname
- Grade
This view could be used to allow others to see the poet's code,
name and surname, but not allow them access to personal
information. Or, a view could be a combination of a number of
tables, such as in this example
:
Poet
- Code
- First name
- Surname
- Age
- Address
- Telephone
Poem
- Poem code
- Poet code
- Title
Subscriber view
- First_name
- Surname
- Poem title
Views are often used for security purposes. Junior developers
may need access to certain portions of a table, but they do not
need access to all the data. What they don't need, even if it is
from the same table, is hidden and safe from manipulation or viewing.
Also, views allow SQL queries to be much simpler. For example,
without views, a developer may have to use the following query:
SELECT first_name,surname,poem FROM poet,poem
WHERE poem.poet_code=poet.code AND poet.title='Once';
With the view, a developer could do the same with:
SELECT first_name,surname,poem from subscriber_view;
Much more simple for a junior developer who hasn't yet learnt how
to do
joins across multiple tables,
and less hassle for a senior developer too!
This has been a brief introduction to relational databases.
Hopefully it's put some of the terms you've come across in
context, and whetted your appetite to explore further.
Additional Resources: