You are on page 1of 14

VIEW MANAGEMENT

Mardhiya Hayati
Stevie Ema W
sub-material
❏ Understanding of view
❏ Creating view
❏ Horizontal view
❏ Vertical view
❏ Create a view call a view
❏ Removing view
❏ Advantages and Disadvantages of Views
Understanding Of “View”

● The dynamic result of one more relational operating on the base relations to
produce another relation.
● A view is a virtual table whose contents are defined by a query. Like a table,
a view consists of a set of named columns and rows of data. Unless
indexed, a view does not exist as a stored set of data values in a database.
● The rows and columns of data come from tables referenced in the query
defining the view and are produced dynamically when the view is
referenced.
Creating a View (CREATE VIEW)

CREATE VIEW view_name

AS

SELECT column_name(s)

FROM table_name

WHERE condition
Horizontal View
A horizontal view restricts a user’s access to selected rows of one or more
tables.
CREATE VIEW Manager3Staff
AS
SELECT * FROM Staff WHERE
BranchNo=’B003’
Execute this statement :

SELECT * FROM Manager3Staff


Vertical View
A horizontal view restricts a user’s access to selected columns of one or more
tables.

CREATE VIEW Staff3


AS
SELECT StaffNo, Fname,Lname,position,sex FROM Staff WHERE BranchNo=’B003’

Execute this statement :

SELECT * FROM Staff3


Create a view call a view
CREATE VIEW Manager3Staff
AS
SELECT * FROM Staff WHERE
BranchNo=’B003’

Call a view :

CREATE VIEW Staff3


AS
SELECT StaffNo, Fname,Lname,position,sex FROM manager3staff
Removing a view

A View is removed from the database with the DROP VIEW statement :

DROP VIEW viewname [RESTRICT | CASCADE]

If CASCADE is specified, DROP VIEW deleted all related dependent objects; in the
other words, all objects that reference the view. This means that DROP VIEW
also deletes any views that are defined on the view being dropped. If RESTRICT
is specified and there are any other objects that depend for their existance on
the continued existance of the view being dropped, the command is rejected.
The default setting is RESTRICT.
WITH CHECK OPTION
1. CREATE VIEW datacustomer
AS
SELECT *
FROM Customers WHERE region_id='WL002'

2. INSERT INTO datacustomer


(customer_id,name,address,region_id,year_of_birth)
VALUES('CUS-11111','testing','medan','WL111','2010')

3. SELECT *
FROM datacustomer

??
WITH CHECK OPTION

1. ALTER VIEW datacustomer


AS
SELECT *
FROM Customers WHERE region_id='WL002'
WITH CHECK OPTION

2. INSERT INTO datacustomer


(customer_id,name,address,region_id,year_of_birth)
VALUES('CUS-222','testing 2','medan','WL111','2010')
Advantages
1. Data Independence

A view can present a consistent, unchanging picture of the structure of the


database, even if the underlying source tables are changed (for example, if
columns added or remove, relationship changed, restructured)

2. Improved Security

Each user can be given the privilege to access the database only though a
small set of views that contain the data appropriate for that user, thus
restricting and controlling each user’s access to the database.
Advantages

3. Reduced Complexity

A view can simplify queries.

4. Convenience

View can provide greater convenience to users as users are presented with
only that part of the database that they need to see. This also reduces the
complexity from the user’s point of view.
Advantages

5. Data Integrity

If the WITH CHECK OPTION clause of the CREATE VIEW statement used, the
SQL ensures that no row that fails to satisfy the WHERE clause of the defining
query is ever added to any of the underlying base tables through the view
Disadvantages

1. Performance

There is a performance penalty to be paid when using a view. In the some


cases, this will be negligible; in the other cases, it may be more problematic.

You might also like