0% found this document useful (0 votes)
21 views6 pages

Lecture 32 VIEWS

A view is a virtual table created by a query that joins one or more tables, allowing for easier data management without storing actual data. Views provide advantages such as ease of use, space savings, and enhanced data security by exposing only certain columns. They can be updated under specific conditions, including restrictions on the SELECT clause and the presence of NOT NULL columns from the base table.

Uploaded by

pesgur2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Lecture 32 VIEWS

A view is a virtual table created by a query that joins one or more tables, allowing for easier data management without storing actual data. Views provide advantages such as ease of use, space savings, and enhanced data security by exposing only certain columns. They can be updated under specific conditions, including restrictions on the SELECT clause and the presence of NOT NULL columns from the base table.

Uploaded by

pesgur2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

VIEW

VIEW is not a physical table, it is a virtual table created by a query joining one or more tables.

CREATE [OR REPLACE] VIEW view_name AS


SELECT columns
FROM tables
Syntax [WHERE conditions];

Start-Tech Academy
CREATE VIEW
VIEW is not a physical table, it is a virtual table created by a query joining one or more tables.

CREATE VIEW logistics AS


SELECT a.order_line,
a.order_id,
b.customer_name,
b.city,
b. state,
Example b. country
FROM sales AS a
LEFT JOIN customer as b
ON a.customer_id = b.customer_id
ORDER BY a.order_line;

CREATE OR REPLACE VIEW can be used instead of just CREATE VIEW

Start-Tech Academy
DROP or UPDATE VIEW
VIEW is not a physical table, it is a virtual table created by a query joining one or more tables.

DROP VIEW logistics;

Example UPDATE logistics


SET Country = US
WHERE Country = ‘United States’;

Start-Tech Academy
VIEW
A view is a virtual table. A view consists of rows and columns just like a table. The
difference between a view and a table is that views are definitions built on top of
other tables (or views), and do not hold data themselves. If data is changing in the
underlying table, the same change is reflected in the view. A view can be built on top
of a single table or multiple tables. It can also be built on top of another view. In the
SQL Create View page, we will see how a view can be built.
Views offer the following advantages:
1. Ease of use: A view hides the complexity of the database tables from end users.
Essentially we can think of views as a layer of abstraction on top of the database
NOTES tables.
2. Space savings: Views takes very little space to store, since they do not store actual
data.
3. Additional data security: Views can include only certain columns in the table so
that only the non-sensitive columns are included and exposed to the end user. In
addition, some databases allow views to have different security settings, thus hiding
sensitive data from prying eyes.

Start-Tech Academy
VIEW
VIEW can be updated under certain conditions which are given below −

• The SELECT clause may not contain the keyword DISTINCT.


• The SELECT clause may not contain summary functions.
• The SELECT clause may not contain set functions.
• The SELECT clause may not contain set operators.
• The SELECT clause may not contain an ORDER BY clause.
• The FROM clause may not contain multiple tables.
NOTES • The WHERE clause may not contain subqueries.
• The query may not contain GROUP BY or HAVING.
• Calculated columns may not be updated.
• All NOT NULL columns from the base table must be included in the view in
order for the INSERT query to function.

Start-Tech Academy

You might also like