You are on page 1of 9

Databases Bachelor IK

March 26, 2012

Science Park A1.04

Instructor: H. Afsarmanesh
University of Amsterdam


Name: ________________________________________________

Student Number: ________________________________________________

Please think carefully about each question before answering. Quality of answers is
important, not quantity. It is advisable to read the entire exam before starting to answer
any of the questions. This exam is open book, but closed notes. Please notice that the
examples which you may provide in your answers must be different than those appearing
in the book and on the slides for the course. Please write all your answers directly on
these exam sheets.
Put your name and student number on the exam sheet. Good Luck!

Question Points Grade
Question 1 (Definitions) 7
Question 2 (ER diagram) 30
Question 3 (Relational schema) 12
Question 4 (Relational algebra) 20
Question 5 (SQL) 27
Question 6 (Normalization) 8

Question 1 (7 points) Definitions
1.1. (2 points)
Name 4 disadvantages of using file systems for organization and storage of data.

1.2. (5 points)
Match each of the terms in the left column with the most closely related concept in the right column, and
write the number next to it.
___Declarative DML
___ DDL
___ Normalization
___ Entity
___ Referential Integrity
___ Primary key
___ third normal form
___ Relationship set
___ Schema
___ View

1. the logical structure of the database
2. consistency among the values of foreign keys in different tables.
3. enables users to retrieve or manipulate data through
specifying what data are needed without stating how to get
those data.
4. results decomposition of relations
5. a mathematical relation among n2 entities, each representing an
entity set
6. can hide information (such as salary) for privacy purposes
7. a candidate key that is selected by the database designer for unique
identification of tuples.
8. an object that exists and is distinguishable from other objects
9. specifies a database schema by a set of definitions
10. for each value of field A, there is a unique non-transitive value for
field B

Question 2 (30 points) ER diagram
Assume that you are hired as a DB developer for a Car Rental Company (CRC). The information
required in the database includes descriptions of cars, cars models, insurances and the repair-
maintenance services provided by subcontractors (i.e. garages), customers, and companys expenses
and incomes:
Cars are of several different models. Each model is described by its id, name, engine size,
fuel type, and number of passengers.
For each specific car, the following information should be provided: id, year manufactured,
registration number, purchase price, purchase date, and rent price.
Every car is insured by one or a number of insurances. Each insurance is specified by its id,
providers company name, type, and description.
Types, prices and subcontractors name (i.e. franchised garages which provides the service)
of each specific repair/maintenance services for cars should be also stored (Type is unique).

The fact of provision of a reparation service for a car should be recorded. The provision date
and the provided service description should be defined.
Company expenses on maintaining and repairing of cars should be registered from all
received subcontractors services. Each expense item should be described with expense
amount, payment status, and the percentage of coverage of this expense by any insurance.
Therefore the expenses information are also directly connected to the insurance information.
A reasonably stable client base exists. The information about clients should include id,
clients names, addresses, credit cards number, and phone numbers.
Contracts with clients should be recorded for the rental cars, indicating the dates of the rent
for each contact.
The records about each income incidence should be stored in relation to each contract. The
payment type, amount, and status should be recorded for each income incidence.
2.1. (14 points)
Below draw an ER diagram for the CRC database, indicating its schema elements.

2.2. (4 points)
Provide a brief definition for the weak entity set. Identify which entity sets (if any) in your E-R diagram of 2.1
are the strong ones and which of them (if any) are the weak ones?

2.3. (4 points)
Provide a short definition (1 to 2 sentences) for identifying relationship sets, and indicate the identifying
relationship sets in your E-R diagram, while specifying which entities sets they identify.

2.4. (3 points)
Provide a short definition (1 to 2 sentences) for total participation of entities in relationships. Identify total
participation of entities in your E-R diagram, and specify from which entity sets to which relationship sets
they are defined.

2.5. (2 points)
For each type of possible mapping cardinality, give one example relationship set case, from your E-R diagram
of 2.1 (if there are any).

2.6. (3 points)
Are there any (i) specialization (/generalization) and/or (ii) aggregation (/specification) abstractions
introduced in your ER diagram? If so, then mention the kind, and for each specify the entity sets and
relationship sets involved in them.


Question 3 (12 points) Relational schema
3.1. (9 points)
Design a good relational schema for the CRC database, which you designed in Question 2. Underline the
primary key in each relation.

3.2. (3 points)
Choose one of the above relations that you have provided above in Question 3.1 which contains one
or more foreign key(s) (Hint: Among different possibilities you can choose a relation with few
attributes). Write below your selected relation schema, and then write a SQL DDL statement to
create this table. (Hint: Primary and foreign keys should be defined.)

Question 4 (20 points) Relational algebra
Consider the following relational database:
Travel-Company (company-name, address, grade, last-year-profit)
Agent-of (agency-name, company-name)
Travel-Agency (agency-name, city)
Company-Manager (company-name, manager-name)
We know that for each travel company, several travel agencies act as its agent. These agencies may be located
in different cities. We also know that each travel agency can also be an agent of many travel companies.
Give a relational algebra expression for each of the following queries:
4.1. (3 points)
Find the company-names for companies that have an agent in city C2.

4.2. (4 points)
Find the name of cities which include at least one travel agency which is an agent of a company with grade 5.

4.3. (4 points)
Find the company-names for companies which do not have any agent in city C5.

4.4 (4 points)
Find the address of the travel company that has more than 8 agents (i.e. agencies acting as its agent).

4.5 (5 points)
Find the manager-names of those companies of which every agency (all of them) which is located in city C2
is their agent.


Question 5 (27 points) - SQL
Consider the following university related relational schema:

Student (snum: integer, sname: string, major: string, level: string, age: integer)
Cource (cname: string, meets_at: time, room: string, fid: integer)
Enrolled (snum: integer, cname: string)
Faculty_member (fid: integer, fname: string, deptid: integer, salary: float)
Department (deptid: integer, dname: string)

Write the following queries in SQL:
5.1. (3 point)
Find the names of all students who have Computer science as major and sort them alphabetically in
descending order.

5.2. (4 point)
Find the names of all Junior students (Level = JR) who have enrolled in a Course taught by Smith.

5.3. (5 point)
Find the names of students who have enrolled in more than 3 courses.

5.4. (5 point)
Find the names of all students who are either a History major or have enrolled in a course taught by Smith.

5.5. (5 point)
Find the names of faculty members who do not teach any course.

5.6. (5 point)
Write a statement for adding 500 euro to the salary of all faculty members of Informatic department.

Question 6 (6 points) Normalization
1. Suppose we have a relational schema R = (A, B, C, D, E) with the following functional
Find 3 candidate keys that you can identify for relation R. Illustrate the correctness of your
results, e.g. through indicating closure of attributes.