Sei sulla pagina 1di 3

HETT 205: DATABASE CONCEPTS

GROUP ASSIGNMENT

Due : 17/07/20

Question 1

Describe how a data model is represented in a relational database, and explain how
one might specify a relational database schema. [5 marks]

Each year the number of tourists coming to Cambridge increases by 10%. Most
of the pressure falls on a limited number of identified sites in the city centre. The
Tourist Board has restricted the size of any group visiting such a site to 20, and
requires a group of ten people or more to get a permit in advance. Most bookings
are made either by tour operators or directly by independent guides: the Tourist
Board will arrange guides for groups if asked to do so.

A database is being installed to coordinate bookings and to provide information


about the opening times of sites. Each site has separate opening times for summer
and winter (owing to college autonomy, changes of season differ from site to site).
Permits are issued to start on the hour or on the half-hour: they are valid either
for 1 hour or for 2 hours, the duration being fixed for each site. The final permits
of each day are timed to expire at the site’s closing time. Each site has a fixed
capacity, and no booking can be accepted that would cause it to be exceeded. The
charge for a permit depends only on the site and the season. (Occasionally sites
are closed for several hours during the normal opening period, for example when
recording is taking place in King’s College Chapel. The protocol is to inform the
Tourist Board at least 6 months in advance.)

The Tourist Board issues permits to visit an identified site at a given time on a
given day, specifying the booking agent and the number in the group. Bookings
can be made up to 6 months beforehand. Permits are issued to registered tour
operators and guides on account, but in all other cases payment must be made in
advance. The data held for registered guides includes not only account details but
also their working hours and charges.

Design a schema for the relational database that is to record this information for
the Tourist Board. You may find it helpful to use domain types DATE, TIME and
MONEY in addition to standard programming language datatypes. You do not need
to specify the transactions that maintain the database, but you should state clearly
any assumptions that influence the schema design.
[15 marks]

1
Question 2

Explain what is meant by a referential integrity constraint in a relational data


model. [4 marks]

The University of Cambridge is determined to maintain its standards under


increasing financial pressure. The government maintains league tables of various
kinds: teaching quality, research rating, unit cost of each student place. The
university still enjoys a high reputation worldwide, but it is in competition
with institutions such as MIT and Stanford whose unit costs are much greater.
The only way to provide facilities such as new research laboratories, graduate
accommodation, a much-needed swimming pool, is by public appeal. It is vital
that there is close liaison between the university development offices and colleges
so that prospective donors do not become alienated by simultaneous demands.

You have been invited by the university to assist in recording details of its
fund-raising. The main purpose is to coordinate the activities of agencies such
as the university and college development offices in their dealings with prospects.
The latter may be alumni of some college, charitable foundations or major
companies with an educational commitment; it is important to record their interests
(bioscience, student welfare, sport) so that they can be approached in a favourable
context; also their potential resources, in order to maximise the possible benefit
to the university. At any time a number of projects need funding: each will be
developed by a single agency, requiring that a target sum be raised by a given date;
projects will have one or more purposes which may be linked with the interests of
prospects. The other main use of the database is to keep a diary of interaction
with prospects; in order to retain their goodwill it is essential to know who has
been invited where and when, and in what context.

Design the schema for a relational database that will record this information. State
clearly any assumptions that you need to make in order to complete the design,
and indicate any difficulties that you foresee in maintaining the database.

[16 marks]

2
Question 3

Suppose we have the following relational schema

Person(pid:integer, name:string, street:string, postcode:string)


Car(cid:integer, year:integer, model:string)
OwnedBy(pid:integer, cid:integer)
AccidentReport(rid:integer, damage:integer, details:string)
ParticipatedIn(pid:integer, rid:integer, cid:integer)

where the underlined attributes represent the primary keys of the associated
relation. The table OwnedBy implements a relationship between persons and cars
using foreign keys. The table P articipatedIn implements a relationship between
persons, accident reports, and cars, where tuple (p, r, c) indicates that the person
p was the driver of the car c associated with the accident report r.

(a) Write an SQL query to return those pid’s of persons driving in at least one
accident, with no duplicates. [2 marks]

(b) Write an SQL query to return all tuples (pid, c), where c is the number of cars
owned by person pid (records where c = 0 do not have to be generated).
[2 marks]

(c) Write an SQL query to return all tuples (cid, c), where c is the number of
persons owning car cid (records where c = 0 do not have to be generated).
[2 marks]

(d ) Write a (nested) SQL query to return all tuples (pid, rid) where pid was
driving in the accident reported in rid, but the car driven by pid is not owned
by pid. [4 marks]

(e) Write an SQL query to return all tuples (rid, c), where c is the number of
drivers involved in the accident reported in by rid (records where c = 0 do not
have to be generated). [2 marks]

(f ) Write an SQL query to return all tuples (rid, c), where c is the number of cars
involved in the accident reported in by rid (records where c = 0 do not have
to be generated). [2 marks]

(g) Do the functional dependencies implied by the schema imply that the results
of queries (e) and (f ) will always be the same? Explain. [2 marks]

(h) Perhaps there is something wrong with this schema. How would you fix the
schema to ensure that results of queries (e) and (f ) would always be the same?
[4 marks]

(i) Convert your SQL statements from (a) to (h) to Relation Algebra [20 marks]

Potrebbero piacerti anche