English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Usage and examples of the SQL VIEW keyword

SQL Keywords Reference

CREATE VIEW (Create View)

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

The CREATE VIEW command creates a view.

The following SQL creates a view selecting all customers from Brazil:

CREATE VIEW [Brazil 
Customers] AS
SELECT CustomerName, ContactName
FROM Customers WHERE Country = "Brazil";

Query view

We can query the following views:

SELECT * FROM [Brazil Customers];

CREATE OR REPLACE VIEW

The CREATE OR REPLACE VIEW command will update the view.

The following SQL adds the 'City' column to the 'Brazil Customers' view:

CREATE OR REPLACE VIEW [Brazil Customers] AS
SELECT CustomerName, ContactName, City
FROM Customers
WHERE Country = "Brazil";

DROP VIEW (Delete View)

The DROP VIEW command will delete a view.

The following SQL deletes the 'Brazil Customers' view:

DROP VIEW [Brazil Customers];

SQL Keywords Reference