Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

VIEW

CREATE VIEW

In SQL, a view is a virtual table based on the result set of an SQL statement.

The CREATE VIEW command is used to create a view.

The provided SQL creates a view that selects all customers from Brazil:

Example

CREATE VIEW [Brazil Customers] AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = “Brazil”

Query The View

The view above can be queried as follows:

Example

SELECT * FROM [Brazil Customers]; 

CREATE OR REPLACE VIEW

The CREATE OR REPLACE VIEW command modifies 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”

DROP VIEW

The DROP VIEW command removes a view.

The provided SQL drops the “Brazil Customers” view:

Example

DROP VIEW [Brazil Customers];