100 Days of SQL

sql

Day 82 – Views

These are virtual tables that are created based on the result set of a query. Views can be used to simplify complex queries by hiding the underlying complexity, or to provide a level of security by controlling data access.

CREATE VIEW vwTopCustomers
AS
SELECT TOP 10 * FROM Customers
ORDER BY Sales DESC

SELECT * FROM vwTopCustomers

In this example, a view named vwTopCustomers is created to retrieve the top 10 customers from the Customers table based on their sales. The view is then queried using a standard SELECT statement.