0% found this document useful (0 votes)
1 views

Lab9-Implementation of Views

This document is a laboratory manual for a Database Systems course at ALQUDS University, focusing on the study and implementation of SQL views. It explains the concept of views as virtual tables, provides syntax for creating, updating, and dropping views, and includes practical assignments related to a schema involving sailors, boats, and reservations. The lab exercises aim to enhance understanding of SQL queries and data manipulation using views.

Uploaded by

Hamza Sayes
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)
1 views

Lab9-Implementation of Views

This document is a laboratory manual for a Database Systems course at ALQUDS University, focusing on the study and implementation of SQL views. It explains the concept of views as virtual tables, provides syntax for creating, updating, and dropping views, and includes practical assignments related to a schema involving sailors, boats, and reservations. The lab exercises aim to enhance understanding of SQL queries and data manipulation using views.

Uploaded by

Hamza Sayes
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/ 5

ALQUDS University

Department of Computer Engineering

Database Systems
Laboratory Manual
0702325

Database Systems Lab


Lab#9: Study & Implementation of Views

Dr.Rushdi Hamammreh ,Eng.Roa AlQuttub 2025


Objective:
To understand the implementation of views.

Theory:
VIEW: In SQL, a view is a virtual table based on the result-set of an SQL statement. A view contains
rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the
database. You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if
the data were coming from one single table. A view is a virtual table, which consists of a set of columns
from one or more tables. It is similar to a table, but it does not store in the database. View is a query
stored as an object.

Syntax:
CREATE VIEW <view name> AS SELECT <set of fields>
FROM relation_name WHERE (Condition)

Example:
CREATE VIEW employee AS SELECT empno,ename,job
FROM EMP
WHERE job = ‘clerk’;

Example:
CREATE VIEW v_sailors_reserved_101 AS
SELECT *
FROM Sailors
WHERE sid IN ( SELECT sid FROM Reserves WHERE bid = 101);

Dr.Rushdi Hamammreh ,Eng.Roa AlQuttub 2025


Updating A View : A view can updated by using the following syntax :

Syntax :
CREATE OR REPLACE VIEW view_name AS SELECT column_name(s)
FROM table_name
WHERE condition

Dropping A View: A view can deleted with the DROP VIEW command.

Syntax: DROP VIEW <view name> ;

Dr.Rushdi Hamammreh ,Eng.Roa AlQuttub 2025


LAB PRACTICE ASSIGNMENT

Consider the following schema:


Sailors (sid, sname, rating, age)
Boats (bid, bname, color)
Reserves (sid, bid, day(date))

1. Find all information of sailors who have reserved boat number 101.
2. Find the name of boat reserved by Bob.
3. Find the names of sailors who have reserved a red boat, and list in the order of age.
4. Find the names of sailors who have reserved at least one boat.
5. Find the ids and names of sailors who have reserved two different boats on the same day.
6. Find the ids of sailors who have reserved a red boat or a green boat.
7. Find the name and the age of the youngest sailor.
8. Count the number of different sailor names.
9. Find the average age of sailors for each rating level.
10. Find the average age of sailors for each rating level that has at least two sailors.

Dr.Rushdi Hamammreh ,Eng.Roa AlQuttub 2025


Post Lab:
a. Find the names of sailors who have never reserved a boat.
b. Find the names and ratings of sailors who have reserved all boats.
c. Find the most frequently reserved boat.
d. Find the sailor(s) who made the most reservations.
e. Find the names of sailors who have reserved boats of more than one color.

Dr.Rushdi Hamammreh ,Eng.Roa AlQuttub 2025

You might also like