View

Create View

Syntax

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

Example

CREATE VIEW [Products Above Average Price] AS
SELECT ProductName, Price
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);

Select View

Syntax

SELECT * FROM [view_name];

Example

SELECT * FROM [Products Above Average Price];

Update View

Syntax

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

Example

CREATE OR REPLACE VIEW [Products Above Average Price] AS
SELECT ProductName, Price
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);

Drop View

Syntax

DROP VIEW [view_name];

Example

DROP VIEW [Products Above Average Price];

Last updated

Was this helpful?