A view is another way to look at table data—sometimes the whole landscape, sometimes one tree. This page explains what a view is, how views differ from base tables, how to write a simple CREATE VIEW, and a first look at updatable vs read-only views.
IBM describes a view as an alternative representation of data that exists in one or more tables. A view can include all or some columns from one or more base tables. Formally, a view is a named specification of a result table. At any moment, the view consists of the rows that its SELECT would return against current data.
| Goal | How views help |
|---|---|
| Security | Omit salary or PII columns; grant SELECT on the view only |
| Simplicity | Pre-join or pre-filter so callers write shorter SQL |
| Stability | Present a stable column list while base tables evolve carefully |
You retrieve from a view much like a table: SELECT with WHERE, GROUP BY, and HAVING as allowed. Views can be based on tables, other views, or combinations. That composability is powerful—and a reason to keep view layers understandable.
| Aspect | Base table | View |
|---|---|---|
| What is stored | Table description + row data | View definition (SELECT) in the catalog |
| Indexes / keys | Allowed on the table | Not created on the view itself |
| SELECT | Yes | Yes—like a table name in FROM |
| INSERT/UPDATE/DELETE | Yes (with privileges) | Only if the view is updatable |
When you CREATE VIEW, Db2 stores the definition in the catalog. It does not store a separate full copy of the view’s data—the rows live in the underlying base tables. Restriction: you cannot create an index for a view, and you cannot create keys or constraints on a view; build those on the base tables.
Columns added to base tables after the view is defined do not appear in the view automatically. If callers need new columns, recreate or adjust the view definition.
Use CREATE VIEW, give a name (up to 128 characters), optionally list view column names, and supply AS SELECT ….
12345CREATE VIEW EMPINFO (EMPLOYEE, FIRSTNAME, LASTNAME, TEAM, JOBTITLE) AS SELECT EMPNO, FIRSTNME, LASTNAME, WORKDEPT, JOB FROM EMP;
EMPINFO renames columns for callers and omits sensitive columns such as salary. Querying the view is like running that SELECT:
123SELECT EMPLOYEE, LASTNAME, TEAM FROM EMPINFO WHERE TEAM = 'A00';
Narrow the view with a WHERE clause in the definition so only certain departments appear:
1234567CREATE VIEW EMPINFO_AC (EMPLOYEE, FIRSTNAME, LASTNAME, TEAM, JOBTITLE) AS SELECT EMPNO, FIRSTNME, LASTNAME, WORKDEPT, JOB FROM EMP WHERE WORKDEPT = 'A00' OR WORKDEPT = 'C01';
CREATE VIEW = save a SELECT under a name. DROP VIEW = remove that saved definition. Privileges on the view control who can use it. The base table remains the source of truth for stored rows.
Whether you can INSERT, UPDATE, or DELETE through a view depends on its definition. If a view includes a foreign key of its base table, insert/update through the view still obeys that referential constraint. If the base table is a parent, deletes through the view follow the same rules as deletes on the base table—when the view allows deletes at all.
Read-only views cannot be used for insert, update, and delete. Complex SELECTs— joins, unions, aggregations, DISTINCT, and similar constructs—often produce read-only views. Simple views on a single base table with a straightforward column list are the usual candidates for updatability (exact rules are version- and definition-specific—verify in the SQL reference before relying on them in production).
1234567891011-- Likely closer to updatable: single table, simple columns CREATE VIEW ACTIVE_CUSTOMER AS SELECT CUST_ID, CUST_NAME, STATUS FROM CUSTOMER WHERE STATUS = 'A'; -- Typically read-only: aggregation CREATE VIEW DEPT_HEADCOUNT AS SELECT WORKDEPT, COUNT(*) AS EMP_COUNT FROM EMP GROUP BY WORKDEPT;
For beginners: use views freely for read simplification and security. Treat updatable views as an advanced design choice—many shops prefer updating base tables explicitly and keeping views read-focused.
A classic pattern is: revoke broad SELECT on the base table from an app id, create a view with only allowed columns/rows, and GRANT SELECT on the view. Callers never see the hidden columns even with SELECT *.
The real toy box is the base table. A view is a special window you cut in a piece of cardboard: maybe you only see the red toys, or you put two boxes side by side in the window. Looking through the window does not make a second full toy box. Sometimes you are allowed to move toys through the window; sometimes the window is look-only (read-only).
1. A Db2 view is best described as:
2. How does a view differ from a base table?
3. CREATE VIEW essentially stores:
4. Read-only views:
5. A common reason to use views is: