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

Usage and examples of the SQL VIEW keyword

Referência de Palavras-chave SQL

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

O comando CREATE OR REPLACE VIEW atualiza a visão.

A seguir, o SQL adiciona a coluna "Cidade" à visão "Brazil Customers":

CREATE OR REPLACE VIEW [Brazil Customers] AS
SELECT Nome do Cliente, Nome do Contato, Cidade
FROM Customers
WHERE País = "Brazil";

DROP VIEW (Excluir Visão)

O comando DROP VIEW exclui uma visão.

A seguir, o SQL exclui a visão "Brazil Customers":

DROP VIEW [Brazil Customers];

Referência de Palavras-chave SQL