💻 Introduction
A View in SQL is a virtual table created from the result of a query. It doesn’t store data itself but provides a saved query that you can reuse like a table. Views help simplify complex queries, improve readability, and enhance security.
1️⃣ CREATE VIEW – Creating a View
The CREATE VIEW statement defines a new view based on a query.
CREATE VIEW EmployeeSalaries AS
SELECT EmpID, FirstName, LastName, Salary
FROM Employees
WHERE Salary > 50000;
Now, you can query the view like a table:
SELECT * FROM EmployeeSalaries;
Tip: Views don’t store data separately; they always fetch the latest data from underlying tables.
2️⃣ ALTER VIEW – Modifying a View
The ALTER VIEW statement modifies an existing view definition.
ALTER VIEW EmployeeSalaries AS
SELECT EmpID, FirstName, LastName, Salary, Department
FROM Employees
WHERE Salary > 60000;
3️⃣ DROP VIEW – Deleting a View
The DROP VIEW statement removes a view permanently.
DROP VIEW EmployeeSalaries;
Tip: Dropping a view doesn’t delete the underlying data. It only removes the saved query definition.
✅ Key Takeaways
CREATE VIEW→ Save a query as a reusable virtual tableALTER VIEW→ Update the definition of an existing viewDROP VIEW→ Remove a view (data remains intact)- Views help simplify complex SQL queries and improve readability
- Good for security → expose only necessary columns to users
📘 Quick Reference – SQL View Operations
| Operation | SQL Command |
|---|---|
| Create View | CREATE VIEW view_name AS SELECT ...; |
| Alter View | ALTER VIEW view_name AS SELECT ...; |
| Drop View | DROP VIEW view_name; |
📚 Continue Learning
💬 Got a question about SQL Views? Drop it in the comments below and let’s discuss!