WHAT IS A VIEW IN SQL

VIEW in SQL

A 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


Leave a Reply

Your email address will not be published. Required fields are marked *