In this tutorial, we will learn how to use, create and drop VIEW
using SQL.
VIEW
is a virtual table which consists of rows and column like a table and it does not physically exist.VIEW
is created by a SQL statement that joins one or more tables.VIEW
.CREATE VIEW viewName AS
SELECT column1,column2,...columnN
FROM tableName
WHERE condition;
CREATE VIEW EmpData_view AS
SELECT EmpName,Salary,City,Country
FROM Employee
WHERE Country='India'
For Selecting data using VIEW
, a query will be:
SELECT * FROM EmpData_view;
A SQL VIEW can be updated with the CREATE OR REPLACE VIEW
statement.
CREATE OR REPLACE VIEW viewName AS
SELECT column1,column2,...columnN
FROM tableName
WHERE condition;
CREATE OR REPLACE VIEW EmpData_view AS
SELECT EmpName,Salary,City,Country
FROM Employee
WHERE Country='India' AND Salary > 18000;
A SQL VIEW
can be deleted with the DROP VIEW
statement.
DROP VIEW viewName;
DROP VIEW EmpData_view;