SQL VIEWview is a virtual table. View doesnot exists actually. It is just created by one or more queries.
There are following concepts under view:
SYNTAX For Creating a view :
CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
A view always shows up-to-date data! The database engine recreates the data, using the view's SQL statement, every time a user queries a view.
SQL Updating a View:
We can update a view by using the following syntax:
SQL CREATE OR REPLACE VIEW Syntax:
CREATE OR REPLACE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
Replace VIEW [Customers List] AS SELECT id,name FROM customers WHERE age=34; SELECT * FROM [Customers List2];
Now we want to add the "Category" column to the "Current Product List" view.
We will update the view with the following SQL:
CREATE VIEW [Current Product List] AS SELECT ProductID,ProductName,Category FROM Products WHERE Discontinued=No;
SQL Dropping a View:
DROP VIEW view_name;