Lab 09: Views
Lab 09: Views
Lab 09: Views
Objective(s) :
To learn the Views
Views
We should be able to use views to:
Reduce apparent database complexity for end users
Prevent sensitive columns from being selected, while still affording access to other
importantdata
Add additional indexing to your database to speed query performance
A view is, at its core, really nothing more than a stored query. What’s great is that you can mix and
match your data from base tables (or other views) to create what will, in most respects, functionjust
like another base table. You can create a simple query that selects from only one table andleaves
some columns out, or you can create a complex query that joins several tables and makesthem appear
as one
Syntax
The syntax for creating a view
CREATE VIEW <view name>
AS
<SELECT statement>
Example 1
We’ll call this one our customer phone list, and create it as CustomerPhoneList_vw
CREATE VIEW CustomerPhoneList_vw
AS
SELECT CustomerName, Contact, Phone
FROM Customers
Example 2
Our manager would like to beable to do simple queries that will tell him or her.What orders have
been placed for what parts and who placed them. So, we create a view that they can perform very
simple queries
Dropping Views
It doesn’t get much easier than this:
DROP VIEW <view name>, [<view name>,[ ...n]]
And it’s gone.
Departemnent of Computer Sciences 3/3 Semester Spring 2016
CSL-220: Database Management System Lab 09: Views
Exercises
1. Create a view to display records of deptno 10 from EMP table with the following attributes:
empno,ename,sal, deptno.
3. Through view created in question 1, update the deptno of employee 7782 from 10 to 20 and
then display all the records from the same view and note which employee record is missing
now, which was displayed in question 2.
4. Create any simple view with base table EMP in such a way that records can only be displayed
but can never be manipulated through this view.
5. Create a view which displays the ename, dname and sal of all the employees of deptno 20.
6. Create a PL/SQL program to display highest salary using view created in question 5.
7. Create a view MY_VU based on the table EMP55 which does not exists in the schema. Now
create the table EMP55 from EMP table having records of deptno=10. Now select all the
records from the view MY_VU.