SQL VIEW
view 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
Note:
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
Example:
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:
Syntax:
DROP VIEW view_name;
id | name | age | city | bill |
1 | Tom | 34 | Paris | 5300 |
2 | Jhony | 51 | London | 400 |
3 | Ram | 64 | Delhi | 20000.7 |
4 | Simon | 23 | Portland | 32.65 |