6 SQL
6 SQL
College of Engineering
Software & Informatics Engineering Department
SQL(CONTINUE)
ND
2 STAGE
Lecturer:
Dr. Hanan Kamal
2
Objectives
• Create View
• Drop View
• View Resolution
• View Materialization
3
Views
View
Dynamic result of one or more relational operations operating
on base relations to produce another relation.
Views
• Contents of a view are defined as a query on one or
more base relations.
• With view resolution, any operations on view are
automatically translated into operations on relations
from which it is derived.
• With view materialization, the view is stored as a
temporary table, which is maintained as the
underlying base tables are updated.
5
View Resolution
Count number of properties managed by each member
at branch B003.
View Resolution
View Resolution
View Resolution
Restrictions on Views
SQL imposes several restrictions on creation and
use of views.
Restrictions on Views
• For example, following query would fail:
SELECT COUNT(cnt)
FROM StaffPropCnt;
SELECT *
FROM StaffPropCnt
WHERE cnt > 2;
19
Restrictions on Views
(b) Grouped view may never be joined with a base
table or a view.
View Updatability
View Updatability
• However, consider again view StaffPropCnt.
• If we tried to insert record showing that at branch
B003, SG5 manages 2 properties:
INSERT INTO StaffPropCnt
VALUES (‘B003’, ‘SG5’, 2);
View Updatability
• If change definition of view and replace count with
actual property numbers:
View Updatability
• Now try to insert the record:
INSERT INTO StaffPropList
VALUES (‘B003’, ‘SG5’, ‘PG19’);
View Updatability
Updatable View
View Materialization
• View resolution mechanism may be slow, particularly
if view is accessed frequently.
• View materialization( is solution) stores view as
temporary table when view is first queried.
View Materialization
• The process of updating a materialized
view in response to changes to the
underlying data is called view
maintenance.
36
View Maintenance
View Materialization
View Materialization
• If insert row for property PG54 at branch
B003 with staffNo = SG37 and rent = 450,
then no new row would need to be added
to materialized view.
Thank you
40