Lesson 25
Advanced Level
25 of 30 lessons
Views
Learn how to create and use views to simplify complex queries and provide data abstraction. Views are virtual tables that simplify data access.
What is a View?
A View is a virtual table based on the result of a SQL query. It stores no data itself but provides a way to simplify complex queries and enhance security.
Creating a View
CREATE VIEW employee_info AS
SELECT employee_id, first_name, last_name, salary
FROM employees
WHERE status = 'ACTIVE';
This creates a view named employee_info that shows only active employees.
Querying a View
SELECT * FROM employee_info;
Modifying a View
CREATE OR REPLACE VIEW employee_info AS
SELECT employee_id, first_name, department_id
FROM employees
WHERE status = 'ACTIVE';
Dropping a View
DROP VIEW employee_info;
Benefits of Views
- Simplify complex queries
- Enhance security by restricting access to sensitive columns
- Improve logical data independence
Practice Task
- Create a view for employees earning more than $5000.