Introduction
Views help keep data safe and simple. They show only what you want others to see.
Jump into concepts and practice - no test required
Views help keep data safe and simple. They show only what you want others to see.
CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
CREATE VIEW EmployeeNames AS SELECT EmployeeID, Name FROM Employees;
CREATE VIEW ActiveCustomers AS SELECT * FROM Customers WHERE Status = 'Active';
CREATE VIEW SalesSummary AS SELECT ProductID, SUM(Quantity) AS TotalSold FROM Sales GROUP BY ProductID;
This example creates an Employees table, adds data, then creates a view showing only IT department employees with their IDs and names. Finally, it selects all from the view.
CREATE TABLE Employees ( EmployeeID INT, Name VARCHAR(50), Salary DECIMAL(10,2), Department VARCHAR(50) ); INSERT INTO Employees VALUES (1, 'Alice', 70000, 'HR'), (2, 'Bob', 80000, 'IT'), (3, 'Charlie', 75000, 'IT'); CREATE VIEW IT_Employees AS SELECT EmployeeID, Name FROM Employees WHERE Department = 'IT'; SELECT * FROM IT_Employees;
Views do not store data themselves; they show data from tables.
Using views can improve security by limiting data exposure.
Views can simplify complex queries for users who don't need all details.
Views act like windows to your data, showing only what you want.
They help keep sensitive data safe and make data easier to use.
You create views with a SELECT query saved as a virtual table.
VIEW in SQL?EmployeeView showing only EmployeeID and Name from Employees table?Employees with columns EmployeeID, Name, Salary, and a view EmployeeView defined as:CREATE VIEW EmployeeView AS SELECT EmployeeID, Name FROM Employees;
SELECT * FROM EmployeeView; return?CREATE VIEW SalesView SELECT OrderID, Amount FROM Sales;
PublicEmployeeData that hides the Salary column from the Employees table but allows users to see EmployeeID, Name, and Department. Which SQL statement correctly creates this view and ensures security by restricting access to sensitive data?