VIEW in SQL

WHAT IS A VIEW IN SQL?

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


Posted

in

Tags:

Comments

Leave a Reply