SQLVIEW Keyword
CREATE VIEW
In SQL, a view is a virtual table based on the result set of an SQL statement.
TheCREATE VIEW command creates a view.
The following SQL creates a view that selects all customers from Brazil:
Example
CREATE VIEW [Brazil Customers] AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = "Brazil";
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = "Brazil";
Query The View
We can query the view above as follows:
Example
SELECT * FROM [Brazil Customers];
CREATE OR REPLACE VIEW
TheCREATE OR REPLACE VIEW command updates a view.
The following SQL adds the "City" column to the "Brazil Customers" view:
Example
CREATE OR REPLACE VIEW [Brazil Customers] AS
SELECT CustomerName, ContactName, City
FROM Customers
WHERE Country = "Brazil";
SELECT CustomerName, ContactName, City
FROM Customers
WHERE Country = "Brazil";
DROP VIEW
TheDROP VIEW command deletes a view.
The following SQL drops the "Brazil Customers" view:
Example
DROP VIEW [Brazil Customers];

