A3.3.5 Database views
HL onlyCommand term: Describe1. From base tables to views
A view is a saved SELECT query that users can treat like a table. Press Next to create a virtual view, change the data, then create a materialised view and watch it go out of date.
2. Live simulation: virtual vs materialised
Change the base table, then query both views. The virtual view re-runs its query every time. The materialised view reads its stored copy, which goes stale (orange) until you refresh it. Watch the work counters.
3. Security lab: who sees what?
Each staff role is granted access to certain views only. Choose a role, then try the statements. Notice which ones are denied and which views cannot be updated.
4. Flip-card deck
Click to flip. Say the answer before you flip.
5. Which benefit of views?
Each scenario uses a view. Which benefit does it show best? Streaks of 3+ score double.
6. 45-second speed round: virtual, materialised or both?
Which type of view does the statement describe?
Learning objectives
By the end of this page you should be able to:
- Describe what a database view is.
- Distinguish between virtual views and materialised (snapshot) views.
- Describe how views hide data complexity, simplify queries and improve security.
- Describe how views affect data consistency, independence and performance.
- Distinguish between read-only and updatable views.
What is a view?
A view is a named, stored SELECT query. Users query it as if it were a table, but it presents data taken from one or more base tables (the real tables).
Two kinds of view
| Virtual view | Materialised (snapshot) view | |
|---|---|---|
| What is stored | Only the query definition | The query and its result rows, on disk like a table |
| When is it calculated? | Every time it is queried | When it is created or refreshed |
| Up to date? | Always shows the current data | Can be stale until refreshed (on a schedule, on demand or on commit) |
| Speed | As slow as the underlying query (joins, aggregates) | Fast to read: the work is already done |
| Storage | Almost none | Extra storage for the copy |
| Good for | Security, simplification, live data | Expensive reports and dashboards on large data |
| Syntax (varies) | CREATE VIEW ... | CREATE MATERIALIZED VIEW ..., REFRESH MATERIALIZED VIEW ... |
Why use views?
- Security: grant users access to a view, not the base table, so they see only certain columns (no phone numbers or medical notes) or certain rows (only their own class).
GRANT SELECT ON GradeReport TO teacher; - Hiding data complexity: users do not need to know how the data is split across tables, keys and joins.
- Query simplification: a long join or calculation is written once; users write
SELECT * FROM GradeReport. - Data consistency: everyone uses the same definition (e.g. how “average grade” is calculated), so reports agree.
- Independence (logical data independence): if base tables are restructured, the view can be redefined so applications using it do not change.
- Performance: materialised views store pre-calculated results, so heavy reports load quickly. (A virtual view does not by itself make a query faster.)
Read-only or updatable?
A view is usually updatable when it is based on one table, with no aggregates, GROUP BY or DISTINCT. An INSERT, UPDATE or DELETE on it is passed to the base table. Views that join tables or aggregate data are usually read-only. Materialised views are normally read-only: change the base tables and refresh. Making a view read-only is itself useful: staff can look but not change.
Use the 中文 button at the top to show or hide the Chinese terms.
| Term | 中文 | Meaning |
|---|
Choose an answer. You get instant feedback.
Score: 0 /
Write your answer first, then reveal the markscheme. These are exam-style practice questions written for this site.
1. Define the term view in a relational database. [2]
2. Outline one difference between a virtual view and a materialised view. [2]
3. A school's STUDENT table contains phone numbers and medical notes. Describe how a view could be used to improve security. [3]
4. Explain why a materialised view may improve the performance of a dashboard that summarises millions of sales records. [3]
5. Explain why a view that joins STUDENT and ENROLMENT is often read-only, while a view of selected columns from STUDENT can be updatable. [4]
6. Describe three benefits of using views in a database. [6]