SQL VIEW is a type of table that only exists virtually, i.e., it has no physical existence. In simpler words, it is a virtual table that is created by applying a query to another table. Such tables are created using the SQL CREATE VIEW
command shown below:
CREATE VIEW myview AS
SELECT columns
FROM tables
WHERE conditions;
If a user wants to delete a SQL VIEW, they can do so with the SQL DROP VIEW
command:
DROP VIEW myview
The VIEW can be permanently deleted using the DROP VIEW
command.
CREATE TABLE Chocolates (Choc_Name varchar(255),Price int);/* Created a table, now let's insert values */INSERT INTO Chocolates (Choc_Name, Price)VALUES ('twix', 20);INSERT INTO Chocolates (Choc_Name, Price)VALUES ('Mars', 30);INSERT INTO Chocolates (Choc_Name, Price)VALUES ('Snickers', 35);INSERT INTO Chocolates (Choc_Name, Price)VALUES ('Hersheys', 25);INSERT INTO Chocolates (Choc_Name, Price)VALUES ('Nutella', 15);/* Create a view */CREATE VIEW Price_greater ASSELECT Choc_Name, PriceFROM ChocolatesWHERE Price >= 25;SELECT * FROM Price_greater;/* Drop view */DROP VIEW Price_greater;