SQL CREATE VIEW Statement

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

CREATE VIEW Syntax

CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

SQL sau đây tạo ra một khung nhìn hiển thị tất cả các khách hàng từ USA:

CREATE VIEW USA AS SELECT customerNumber,customerName, country 
FROM customers 
WHERE country = 'USA';

SQL CREATE OR REPLACE VIEW Syntax

CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

SQL sau đây thêm cột "phone" vào chế độ xem "USA":

CREATE OR REPLACE  VIEW USA AS SELECT customerNumber,customerName, country, phone 
FROM customers WHERE country = 'USA';

SQL Dropping a View

DROP VIEW view_name;
DROP view USA;

Last updated