A View is a virtual table based on the result set of a SQL query. It presents data from one or more tables without storing the data physically.
CREATE VIEW employee_details AS
SELECT employee_id, first_name, last_name, department, salary
FROM employees
WHERE status = 'ACTIVE';
employee_details now acts like a table for querying active employees.SELECT * FROM employee_details WHERE department = 'Sales';
| Type | Description |
|---|---|
| Simple View | Based on a single table without functions or groups. Often updatable. |
| Complex View | Based on multiple tables, includes joins, aggregates, group by, etc. Usually read-only. |
| Materialized View | Stores the result physically for faster access, needs refreshing. |
Updatable Views allow INSERT, UPDATE, DELETE through the view if:
Otherwise, views are read-only.
Example of updating through view:
UPDATE employee_details SET salary = salary * 1.1 WHERE employee_id = 101;
CREATE OR REPLACE VIEW employee_details AS
SELECT employee_id, first_name, last_name, department, salary
FROM employees
WHERE status = 'ACTIVE' AND department IS NOT NULL;
DROP VIEW employee_details;
| Feature | Description | Example |
|---|---|---|
| Create View | Defines a virtual table | CREATE VIEW v AS SELECT... |
| Query View | Access data through the view | SELECT * FROM v; |
| Updatable View | Allows DML operations if conditions met | UPDATE v SET salary =...; |
| Materialized View | Stores data physically, requires refresh | CREATE MATERIALIZED VIEW mv AS... |
| Drop View | Removes the view definition | DROP VIEW v; |
Open this section to load past papers