M359 Mock Exam
(Exam was given in spring 2009)
Note: actual number and distribution of marks could be different
Branch Name:
Exam Type:
Midterm
2009/2010
Academic Year:
Form:
A
X
Final
X
Semester:
B
First
X
Second
Summer
Course Name/No. : Relational databases: theory and practice/M359
Exam Date: 24 May 2010
Exam Time:
3
hrs.
Section Number:
Question
No.
Earned
Points
First Marker’s
Signature
Second Marker’s
Signature
Part I
Part II
Part III
Part IV
Total
Quality
Assurance
Responsible
Signature
Form A Page 1 of
14
Reviewer’s
Signature
PART I. Answer ALL of the following 10 Multiple Choice Questions. Each question is
worth 1.5 marks.
1. A weak entity type is called weak because:
A) Instances of the entity type cannot exist without there being instances of another
entity type
B) It has a limited ability for being converted into a relational table
C) It does not support all types of relationship types
D) It cannot supports more than one relationship type at the same time
2. Which of the following is true about the three schema architecture?
A) Specifies two different types of mappings
B) Supports two different types of data independence
C) Contains three different types of schemas
D) All of the above
3. How are relationships represented in the relational model?
A) Using foreign keys
B) Using relations
C) Either A or B above
D) None of the above
4. What will the relational operator divide produce when dividing a relation
registration(StudentID, Name, CourseNo, TutorID) by a relation tutor(TutorID,
TutorName)
A) The relation result(StudnetID, Name, CourseNo)
B) The relation result(TutorID, TutorName)
C) The relation result(StudentID, Name, CourseNo, TutorID, TutorName)
D) Will not work
5. Which of the following are options usually provided in relational databases for
deleting referenced tuples:
A) If a record is deleted in the referenced relation, then all matching records in the
referring relation will be deleted also
B) Disallow deleting referenced tuples altogether
C) A delete in the referring table results in other deletes in the same table
D) A and B above
6. A lossy decomposition is one that results in.
A) Necessary loss of tuples when we reconstruct the original relation through a
join
B) Extra tuples that appear in the reconstructed relation
C) Loss of the attribute values in the form of NULL values appearing in the
reconstructed relation
D) Loss of entire attributes in the reconstructed relation
Form A Page 2 of 14
7. The SQL queries:
SELECT AVG(salary) AS average_salary FROM employee
SELECT AVG (DISTINCT salary) AS average_salary FROM employee
A) Will always give identical results
B) Will produce a multi-valued table
C) Could produce different results
D) Are invalid
8. Which of the following is not true about logical processing models
A) They define exactly the logical behavior of SQL queries
B) They help in verifying the meaning of queries
C) They can be represented as a diagram
D) They define precisely how the computer will process the query
9. Using a natural joins is
A) Desirable as it reduces the complexity of the query
B) Not recommended as it reduces the maintainability of the database
C) Could alter the behavior of databases if the database is restructured
D) Both B and C above
10. Which of the following is not true about ad hoc creation of tables by users in
database development
A) Could result in data islands
B) Could result in great improvement is the efficiency of database development
C) Could lead to an unstable database environment
D) Could result in multiple copies of potentially inconsistent data
PART II. Answer ANY 7 of the following 9 short answer questions. Each question is
worth 3 marks.
11. Explain what is meant by unproductive maintenance problem in the old file system
approach and how the database approach addresses it.
12. Describe briefly the differences between the Information Systems (IS), Information
management (IM), and Information Technology (IT) strategies.
13. Explain the statement: “join is a refinement of Cartesian product”. Suppose we wish
to join tables S(A, B) and T(C, D) on attributes B and C. Write a simple SQL query
to make the join using a refinement of Cartesian product.
14. The basic operation to normalize a table R – regardless of which normal form – is to
identify an offending functional Dependency (FD) then to successively split it into
two tables until all tables are normalized. Describe how this can be done in such a
way to guarantee non-loss decomposition?
15. Explain four different means by which the relational model can represent constraints.
Form A Page 3 of 14
16. In the pure relational model, explain why we can’t represent a relationship type by a
posted foreign key when both sides of the relationship have optional participation
“constraints”.
17. Explain the statement:
“The HAVING clause is to groups what the WHERE clause is to rows.”
18. A query written using subqueries can often be re-written using joins and vice versa.
Discuss when are subqueries necessary, when are joins necessary, and what factors
affect the choice when both options are feasible.
19. Explain the concept of isolation levels and why this is needed in databases where
concurrent access is required? What is the highest isolation level?
Form A Page 4 of 14
PART III. Answer ANY 4 of the following 5 questions. Each question is worth 8 marks.
20. In order to pass a course, a student needs to receive at least 20 marks in the midterm
assessment (MTA), 20 marks in the Final, and 50 marks in the total score
(MTA+Final). Complete the following cursor declaration for a procedure that will
receive as input an integer parameter (margin) and will automatically identify all
students who have a shortfall of margin marks to pass the course, whether this
shortfall is in the MTA, in the Final, or in the total score. The procedure should take
its input from the table:
course_marks (a_sid, a_mta, a_final)
and insert all marginal students in the table:
marginal_cases (studnet_id, mta_marks, final_marks):
CREATE PROCEDURE identify_marginals (IN margin INTEGER)
BEGIN
DECLARE sid INTEGER;
DECLARE mta INTEGER;
DECLARE final INTEGER;
DECLARE loop_control CHAR(5);
DECLARE course_marks_cursor CURSOR FOR
____________________________
____________________________ ;
OPEN course_marks_cursor;
SET loop_control = '00000';
WHILE loop_control <> '02000' LOOP
FETCH course_marks_cursor INTO ________________ ;
SET loop_control = SQLSTATE;
IF ((((20-mta) <= ________ ) AND ((20-mta)>0))
OR (((20-final)<= _______ ) AND ((20-final)>0))
OR (((50-mta-final)<= ________) AND ((50-mta-final)>0)))
AND (loop_control <> '02000')
THEN INSERT INTO marginal_cases(student_id, mta_marks,
final_marks)
__________________________________;
END IF;
END LOOP;
CLOSE _______________ ;
END
Form A Page 5 of 14
21. A car registration database that keeps information only on currently registered cars
(previous registrations are not part of this database) uses the Cars table below.
There is a globally unique serial number for each car but the license plate number is
only unique within each country. A car with a license plate in a certain country must
be registered in an office located in that country.
Cars (make, model, year, serialNo, color, licensePlateNo, country,
registrationOffice, ownerId)
i.
ii.
iii.
iv.
Write down a set of functional dependencies that covers all the dependencies
in this scenario.
Determine all the candidate keys for the relation Cars
Select one of the candidate keys identified to be the primary key. Based on
this primary key, what is the highest normal form to which the relation Cars
conforms? Explain your answer in two steps: 1. by showing that it satisfies
the definition of this normal form and 2. By showing that it violates the
definition of the next higher normal form.
Normalize the relation Cars to the next higher normal form. Indicate to
which normal form(s) the resulting relations now conform? and why?
Hint: show that the relation conforms to the identified normal form and then
show that it violates the next higher normal form.
22. In a car repair shop database, it is desired to build a database that includes
technicians, cars, repairs, procedures, and parts.
Each technician may provide several repairs for several cars, but does not have to
participate in any repair at all. Each repair specified is for one technician and one
car. No repair exists without an associated technician and an associated car. A
car may undergo several repairs but may not need any repairs. A car may suffer
multiple problems, and therefore require several repairs from each technician. For
each repair, the date the car entered the shop is recorded along with the reason (for
example car would not start). Each repair may require several procedures (for
example, an accident repair may require body work and replacement of some parts),
but sometimes, the repairs are simple and will not require the specification of any
procedures. Each procedure may require the purchase of several part types (a
shopping list). A part type may participate in several procedures. Each procedure
necessarily requires some part types, but a part type may or may not participate in
any procedures.
Give a conceptual data model (CDM) for this application using the EntityRelationship model. Give all degree and participation conditions details.
23. Give a relational representation for the following E-R diagram fragments:
i.
Employee (EmpID, EmpName, Address, Tel)
Committee (ComitteeCode, title, purpose, dateFormed)
Form A Page 6 of 14
ii.
A (a1, a2, a3)
B (b1, b2, b3)
24. Give a relational representation for the following E-R diagram fragment, including
any required constraint declaration.
Departments (DeptNo, DeptName, Location)
Employees (EmpId, EmpName)
PART IV. Answer ANY 4 of the following 5 questions. Each question is worth 8 marks.
Use the following to answer questions 25-29:
The Hospital relational headings
Team (TeamCode, TelephoneNo, StaffNo)
ConsistsOf (StaffNo, TeamCode)
Doctor (StaffNo, DoctorName, Position)
Specialist (StaffNo, Specialism)
Patient (PatientId, PatientName, Gender, Height, Weight, StaffNo, WardNo)
Ward (WardNo, WardName, NumberOfBeds)
Nurse (StaffNo, NurseName, WardNo)
Supervises (StaffNo, Supervisor)
Treatment (StaffNo, PatientID, StartDate, Reason)
Prescription (PrescriptionNo, Quantity, DailyDosage, StaffNo, PatientId, StartDate, DrugCode)
Drug (DrugCode, DrugName, Type, Price)
Form A Page 7 of 14
25. Write a SQL query to list prescription number, the staff number, and the patient id
together with a new column called total_dosage that is the product of quantity
multiplied by the daily dosage.
26. Write a SQL query to list the patient ID and patient name and staff number of the
treating doctor for all male patients whose weight to height ratio is below 2.0 and
whose name starts with the letter M
27. Write a SQL query to find the names of all female patients who are treated by a
doctor whose position is consultant, along with the name of the doctor and the name
of the ward and in which the patient is being treated. Formulate your query as a
restriction of a Cartesian product of the relations involved. Do not use the key word
JOIN in your query.
28. Write a SQL query to get for every patient the patient id and the highest daily dosage
this patient receives from any drug (i.e. regardless of the drug). Only include patients
who take more than one drug.
29. Write an SQL query to get all patient details for all patients whose weight is above
the average of the patients of the same gender in the same ward by more than 20%
Form A Page 8 of 14
Reference Sheet
Properties of Functional Dependencies:
Property 1: combining functional dependencies
If A B and A C, then A ↦ B, C
Property 2: extending determinants
If A
C and A is a subset of B, then B
Property 3: transitivity
If A ↦ B and B ↦ C then A
C
C
Property 4: augmentation
If A ↦ B, then A, C ↦ B, C
Normal Forms:
1NF: A relation is in first normal form (1NF) if and only if it has no duplicate
tuples and in each tuple, each value of every attribute is a single value.
2NF: A relation is in second normal form (2NF) if and only if every non-primary
key attribute is fully functionally dependent on the primary key.
3NF: A relation is in third normal form (3NF) if and only if it is in 2NF and no
nonprimary key attribute is transitively dependent on the primary key.
Definition:
An attribute A is transitively dependent (TD) on a set of attributes X in a relation R if
there is a set of attributes Y such that all the following properties hold:
TD(i) X ↦ Y and Y ↦ A.
TD(ii) It is not true that Y ↦ X.
TD(iii) A is not an attribute of either X or Y.
We included TD(ii) to rule out the situation where Y is an alternate key.
BCNF: A relation is in Boyce–Codd normal form (BCNF) if and only if each
irreducible determinant of a non-trivial FD is a candidate key.
Definitions:
A determinant A in A ↦ B is irreducible if there is no proper subset S of A such that
S↦B
A trivial FD is one in which the right hand side is a subset of the left hand side
Form A Page 9 of 14
Answer Key
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
A
D
C
D
D
B
C
D
D
B
Unproductive maintenance occurs in the old file system approach when applications
programs need to be maintained or re-written due to restructuring in the underlying
file that is unrelated to the current application and does not lead to any
improvements in it. It is usually related to additional requirements in other
application programs, resulting in the need to restructure the underlying file(s). This
problem is addressed in database management systems by introducing the concept of
data independence in which application programs are independent of the file
structures.
Information Systems (IS) strategy is focused on the business improvement and what
it can be brought about by application of appropriate information systems. The
Information Management (IM) strategy focuses on people and the management
aspects of the information systems. Finally, the Information Technology (IT)
strategy focuses on what technologies should be used, and on the development
aspects of the technology.
A Cartesian Product operation produces all possible pairs of tuples. We can achieve
the effect of join by further restricting the result of the Cartesian product to ensure
that the join attributes coming from both tables fulfill the join condition.
SELECT *
FROM S, T
WHERE S.B = T.C;
We proceed in each step by projecting R:
First, over the left- and right-hand sides of the FD to give S, and then over all the
attributes of R except those which form the right-hand side of FD, to give T. This
process guarantees non-loss decomposition by the theory of I.J.Heath.
1. By specifying primary keys
2. By specifying foreign keys
3. By specifying alternate keys
4. By specifying general constraints
5. By specifying domains
The pure relational model requires all fields to have a value. No matter which side
we use to post a foreign key, we will not be able to guarantee the optional
participation since this will require the posted foreign key to have no value.
The WHERE clause operates at the level of rows, meaning that each row is filtered
individually by applying the condition in the WHERE clause to it. If it passes the
test, it is included in the result. The having clause operates at the level of groups,
meaning that each group if filtered individually by applying the condition in the
HAVING clause to it. If the group as whole passes the test, it is included in the
result, otherwise, it is rejected.
Form A Page 10 of 14
18. A join is necessary when the final table includes data from both tables because
fields in tables referred to only inside a subquery are inaccessible in the SELECT
Clause.
A subquery is necessary when a comparison is to be made with an aggregate
function applied to the second table or lists of values from all the rows because
this requires two levels of evaluation, not available in queries with joins only.
When there is a genuine choice between a join and a subquery, there are two
factors to consider:
Which formulation seems more naturally based on the English request.
Which formulation is likely to be most efficient
19. Isolation levels refer to the ability to define multiple levels of concurrency which
differ in how strictly concurrently running transactions are isolated from each other
and to also define the level of concurrent access for a transaction. User-selectable
isolation levels allow a choice between accuracy of data and speed of execution.
The highest level of isolation is known as serializable isolation, which guarantees
serializable execution of a transaction. Lower isolation levels may result in one of
the concurrency problems occurring, but generally allow quicker execution.
20. CREATE PROCEDURE identify_marginals (IN margin INTEGER)
BEGIN
DECLARE sid INTEGER;
DECLARE mta INTEGER;
DECLARE final INTEGER;
DECLARE loop_control CHAR(5);
DECLARE course_marks_cursor CURSOR FOR
SELECT a_sid, a_mta, a_final
FROM course_marks;
OPEN course_marks_cursor;
SET loop_control = '00000';
WHILE loop_control <> '02000' LOOP
FETCH course_marks_cursor INTO sid, mta, final ;
SET loop_control = SQLSTATE;
IF ((((20-mta) <=margin) AND ((20-mta)>0))
OR (((20-final)<=margin) AND ((20-final)>0))
OR (((50-mta-final)<=margin) AND ((50-mta-final)>0)))
AND (loop_control <> '02000')
THEN INSERT INTO marginal_cases(student_id, mta_marks,
final_marks)
VALUES (sid, mta, final);
END IF;
END LOOP;
CLOSE course_marks_cursor;
END
21. i.
FD1: serialNo make, model, year, licensePlateNo, country, registrationOffice,
ownerId
FD2: licensePlateNo, country serialNo
FD3: registrationOffice country
Form A Page 11 of 14
ii.
SerialNo
(licensePlateNo, country)
iii. If the student selects serialNo as the primary key, then the relation is Cars in 2NF
only as follows:
1. Cars is in automatically in 2NF because its primary key is simple, and all
relations with simple (non-composite) primary keys are in 2NF.
2. Since serialNo registrationOffice and registrationOffice country, and all
three conditions of a transitive dependence are satisfied, it follows that a
nonprimary attribute (country) is transitively dependent on the primary key
(serialNo), therefore, the relation Cars in not in 3NF.
If the student picks (licensePlateNo, country) as the primary key, then the relation
Cars is in 3NF, as follows:
1. Cars is in 2NF because neither licensePlateNo nor country is a determinant
of any other attribute. Therefore, every non-primary attribute is fully
functionally dependent on the primary key. This establishes 2NF.
2. Although (licensePlateNo, country)
registrationOffice and
registrationOffice country, this does not satisfy the conditions of a
transitive dependency. Namely, condition TD(ii) is not satisfied because
country is in fact an attribute of (licensePlateNo, country) – i.e. A is an
attribute of X. Therefore, the relation Cars in 3NF.
3. registrationOffice is a determinant in the non-trivial FD: registrationOffice
country, yet it is not a candidate key as it does not determine any other
attribute. Therefore, relation Cars is not in BCNF.
iv. Regardless of which key the student has chosen, the answer to this part is as
follows:
Cars (make, model, year, serialNo, color, licensePlateNo, country, ownerId)
RegistrationOffices (registrationOffice, country)
Both the tables will be in BCNF as all determinants of a non-trivial FDs are
candidate keys.
Form A Page 12 of 14
22.
Technicians (TechnicianID, Name, …)
Repairs (repaireId, date, reason, description, …)
Cars (make, model, year, …)
Procedures (procedureID, description, …)
Parts(PartTypeID, description, …)
23. relation Employee
EmpID: EmpIds
EmpName: Names
Address: Addresses
primary key EmpID
relation Committee
CommitteeCode: ComitteeCodes
Tel: TelephoneNumbers
DateFormed: Date
CommitteHead: EmpIds
primary key CommitteeCode {Heads is 1:1}
alternate key CommitteeHead: StaffNos {mandatory participation of Committee in
Heads relationship}
foreign key CommitteeHead references Employee
24. relation Employees
EmpId: EmpIds
EmpName: Names
DeptNo: DeptNos
primary key EmpId
{relationship WorksIn}
foreign key DeptNo references Deptartment
relation Departments
DeptNo: DeptNos
DeptName: DeptNames
Location:Locations
primary key DeptNo
Form A Page 13 of 14
25.
26.
27.
28.
29.
constraint ((project Departments over DeptNo) difference (project Employees
over DeptNo)) is empty
SELECT PrescriptionNo, StaffNo, PatientID, Quantity*DailyDosage AS
total_dosage
FROM prescription
SELECT patient_id, patient_name, staff_no, height/weight
FROM patient
WHERE height/weight < 3
AND gender ='M'
AND patient_name like 'M%'
SELECT patient_name, doctor_name, ward_name, position
FROM doctor, patient, ward
WHERE doctor.staff_no = patient.staff_no
AND patient.ward_no = ward.ward_no
AND position = 'consultant'
AND gender = 'F'
SELECT patient_id, max(daily_dosage) from prescription
GROUP BY patient_id
HAVING count(distinct drug_code) > 1
SELECT *
FROM patient p1
WHERE weight > 1.2*(select avg(weight)
FROM patient p2
WHERE p1.gender = p2.gender
AND p1.ward_no = p2.ward_no)
Form A Page 14 of 14
© Copyright 2026 Paperzz