A VIEW in SQL is a virtual table showing up-to-date result-set of SQL statements.
Unlike a real table, a view does not exist in the database as a
stored set of data values. Instead, the rows and columns of data visible through the view are
the query results produced by the query that defines the view.
HOW TO CREATE VIEW IN SQL?
Syntax of CREATE VIEW in SQL-
CREATE VIEW <view_name> AS
SELECT column_name1,..column_nameN
FROM <table_name> WHERE <condition(s)>;
Example of VIEW in SQL-
CREATE VIEW [Germany Customers] AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country= โGermanyโ; โTo create view Germany Customers
SELECT * FROM [Germany Customers]; โTo execute or query the view
HOW TO DELETE VIEW IN SQL?
Syntax to delete view in SQL-
DROP VIEW view_name;
Example to delete view in SQLโ
DROP VIEW [Germany Customers];
HOW TO UPDATE VIEW IN SQL?
CREATE OR REPLACE VIEW <view_name> AS
SELECT column_name1,..column_nameN
FROM <table_name> WHERE <condition(s)>;
Example of CREATE OR REPLACE VIEW-
CREATE OR REPLACE VIEW [Germany Customers] AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country= โGermanyโ; โTo create view Germany Customers
Leave a Reply