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;



table 'customers'

id

name

age

city

bill

1Tom34Paris5300
2Jhony51London 400
3Ram64Delhi20000.7
4Simon23Portland32.65



Online Execute/Compile