What is a VIEW?
- SQL course
- Intermediate
- Lesson 71/115
- 4 min
Create a virtual table.
What is a VIEW?
A VIEW is a virtual table. It stores a named query and can be queried like a table.
CREATE VIEW active_customers AS
SELECT * FROM customers WHERE status = 'active';Virtual table for active customers.
The view active_customers is created. All columns are selected from customers. WHERE keeps only the rows where status = 'active' holds.
What is a VIEW? — details
A VIEW stores no data; it stores the query. When queried, the underlying query runs.
For example, if you save a frequently used JOIN as a view named active_customers, everyone can reach the same data without knowing the complex query.
Practice What is a VIEW?
Create a VIEW named active_customers.
Starter code
-- virtual table
CREATE VIEWSample solution
CREATE VIEW active_customers AS
SELECT * FROM customers WHERE status = 'active';Expected output
VIEW oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does a VIEW store?
- An index
- The query Correct answer
- The data
- A trigger
Explanation: A VIEW stores the query, not data.
2 Add CREATE VIEW
CREATE ____ active_customers AS
SELECT * FROM customers WHERE status = 'active';
CREATE VIEW active_customers AS
SELECT * FROM customers WHERE status = 'active';
Explanation: CREATE VIEW stores a query under a name that you can then query like a table.
3 What is a VIEW: match the terms
| Term | Meaning |
|---|---|
VIEW |
virtual table |
CREATE |
create |
SELECT |
query |
AS |
name |