Professional Documents
Culture Documents
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)
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 :
Call a view :
A View is removed from the database with the DROP VIEW statement :
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'
3. SELECT *
FROM datacustomer
??
WITH CHECK OPTION
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
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