Professional Documents
Culture Documents
Chapter 11 Answers
Chapter 11 Answers
Chapter 11 Answers
Question 11.02
No, because each relationship comprises a forward and backward component so if the position of the entities
is reversed the relationship components are changed in accordance with this.
Task 11.01
The conceptual E–R diagram in its simplest form can be shown as:
The only sensible diagram has the Cruise entity at the centre.
There are some obvious arguments for one of the M:M relationships. A cruise visits more than one port and
a port is visited by more than one cruise. For the other relationship the question is whether the database should
have a permanent entity for Passenger. If this is true, then a passenger can go on more than one cruise.
Note that PortName must have unique values; if two ports have the same name they could be modified to
distinguish them so that there is no need to create a new attribute PortID.
Note the compound primary keys containing two individual foreign keys.
There is a subtlety in this scenario. If each cruise is defined to be an individual one on a certain date the above
key table is fine. However, if the database has been set up with Cruise defined as a package that is on offer more
than once, the primary key defined here no longer has unique values. To make the primary key values unique, a
date attribute could be included.
Question 11.03
It would be possible to design a database where a band could be classified permanently as a headlining one.
However, the assumption here is that a band may or may not be headlining a particular booking. This means
that the Headlining attribute must be in the Band-Booking table.
Task 11.02
The list of attributes can be represented as:
(OrderNumber, Date, CustomerNumber, CustomerName, CustomerAddress, SalesRepNumber, SalesRepName,
(ProductNumber, Description, Quantity, Price))
Task 11.03
This SQL matches the table designs identified at the end of Worked Example 11.02.
CREATE TABLE Venue(
VenueName varchar(25),
VenueAddress1 varchar(25),
VenueAddress2 varchar(25));
BandName varchar(25),
NumberOfMembers integer);
BookingID varchar(8),
Date date,
VenueName varchar(25));
Venue(VenueName));
BandName varchar(25),
BookingID varchar(8),
Headlining character);
Note that the order in which this SQL is presented is important. Before a foreign key constraint is added, the
reference table must have been created. Note that the ALTER command does not have to come immediately after
a table is created.
Exam-style Questions
1 a i 1 mark each for any of the following. (max 2)
Each row of the table is a tuple (1), each column an attribute (1). For each tuple an attribute has a
single value or no value (1). The same value can occur more than once for an attribute unless unique
values have been stipulated (1).
ii 1 mark each for any of the following. (max 4)
Every table must have a primary key (1). The primary key must be a single attribute or a combination
of attributes (1). The primary key must have unique values (1). There is no attribute in this table nor a
suitable combination of attributes that is suitable as a primary key (1). An attribute StudentStudyID
could be added (1) and assigned as a primary key (1).
iii No, there is a repeating group (1). For each student there is more than one value for subject, level and
subject teacher (1).
b i The Student table has a primary key StudentName (1), which is a foreign key in StudentSubject (1).
StudentSubject has a compound primary key StudentName + Subject (1).
(1)
It is M:1 because a dinner is for one Client at one Venue but one Client can book many Dinners and one
Venue can be used for many Dinners. (1)
For each of the remaining relationships the following diagram is correct:
(1)
This is M:M because one Dinner needs many staff and provides many dishes. One staff works at many
Dinners and one Dish can be served at many Dinners. (1)
3 a 3 marks for all non-repeating attributes, 2 marks for all repeating OR 1 mark each for any non-repeating
and any repeating: (BookingNumber, Hotel, HotelAddress, Rating, (Date, RoomType, NumberOfRooms,
RoomRate)).
b 1 mark for two sensible tables, 1 mark for primary keys, 1 mark for other attributes:
Booking(BookingNumber, Hotel, HotelAddress, Rating)
RoomTypebooking(BookingNumber(fk), RoomType, Date, NumberOfRooms, RoomRate).
c 2 marks for keys, 1 mark for other attributes, 2 marks for explanation:
To convert to 2NF only the repeating group data has to be changed. The second table definition changes
to the following two:
RoomTypebooking(BookingNumber(fk), RoomType(fk), Date, NumberOfRooms)
RoomType(RoomType, RoomRate)
In the RoomTypebooking table a composite primary key is needed in which both attributes are foreign
keys. Note that this design assumes that the RoomRate is the same for all rooms of a given type.
You might wish to discuss how the database would be designed if this were not the case.
d HotelAddress and Rating are dependent on Hotel (1), which is not the primary key (1) so the Booking table
is not in 3NF.
StudentID varchar(5),
StudentName varchar(25),
StudentOtherName varchar(25),
SubjectName varchar(25),
SubjectTeacher varchar(25),
);
StudentID varchar(5),
SubjectName varchar(25),
WeekNumber integer,
Day integer,
PeriodNumber integer);
For each table 1 mark each for Create Table, the correct attributes and correct parentheses. (max 5)
b ALTER TABLE Subject ADD PRIMARY KEY (StudentID);
Student(StudentID));
Subject(SubjectName));
FROM Student
One mark each for SELECT StudentName, FROM Student, ORDER BY, DateofBirth, DESC.
Note that the use of DESC puts the largest value for the date first, so that the ordering starts with the
lowest age. Also note that the use of ORDER BY does not imply that the attribute used is output by the
SELECT statement.
d The tutorial table needs a TutorialID as the primary key (1) because the same combination of StudentID
and SubjectName will occur for many different weeks and possibly more than one period. The primary
key must have unique values (1).
FROM STUDENT
iv This requires an inner join. Depending on which DBMS is used, the keyword INNER JOIN might or might
not be required. The two options are illustrated here.
SELECT STUDENT.LastName
SELECT STUDENT.LastName
ON CLASS-GROUP.StudentID = STUDENT.StudentID
Cambridge International AS & A Level Computer Science 9608 paper 11 Q8 June 2016
6 This is Question 9 in 9608 Paper 12 November 2016. At the time of writing the published mark scheme is
available on the Cambridge International School Support Hub (requires registration). The Examiners Report
for the November 2016 series is also available there and this may contain comments specific to this question.
The following are what the author of this chapter in the Teacher Resource would suggest as reasonable
answers with alternatives suggested where appropriate. Where a suggested answer includes bullet points,
each bullet point would be worth one mark up to the maximum mark allocation for the question
a The following are the suggested answers to a part of Question 5 above. They are equally applicable here:
If data is stored in a file there cannot be security measures applying to just part of the file.
This requires a number of files to be created each suited for a specific use.
These files may contain the same data; there is data redundancy which may lead to data
inconsistency if there is editing of only some of the instances of a data item.
Files have to store data in a format and structure that is understood by any program that uses the file
which is described as data dependency.
c
Table name Primary key Foreign key
Chef ChefID
Cake CakeName ChefID
CakeName
Cake-Ingredient CakeName+IngredientName
IngredientName
Ingredient IngredientName
This assumes that each cake has an individual name and the same applies for ingredient names.
It allows for two chefs to have the same name.
4
With a scenario like this there is often an obvious choice for an entity to be placed first at the centre of the
diagram. This entity will have more than one connected entity and will have attribute values that will change
on a regular basis. Coach trip fits this profile. A special point to note is that the coach will not always have the
same driver so there is no direct relationship between coach and driver. Finally, note that only Destination is
involved in a M:M relationship.
5 Table name Primary key Foreign key
Film FilmID
Cast-member FilmID&ActorName FilmID, ActorName
Actor ActorName
It is worth noting that the entity-relationship diagram given in the question has a link entity because the
relationship between Actor and Film would be M:M. If there is a request to draw such a diagram, the crow’s
feet must be in the correct positions as shown in the question’s diagram. In order to answer the question, it is
important to remember that the foreign key goes at the M end of a relationship so that Cast-member must
have two foreign keys. The combination of these creates a sensible primary key so it is not necessary to
create a separate primary key. Finally, because a primary key must have unique values, FilmName is not
sensible as a primary key because films are often re-made with the same title. The assumption here is that all
film actors have unique names, which may not be true.
a SELECT OrderID FROM Order WHERE CustomerID = 365 AND OrderDate > 2016-
01-01
b SELECT ProductID, Quantity
FROM Order-Product, Order
WHERE Order.CustomerID = 365
AND Order.OrderID = Order-Product.OrderID
AND OrderDate = 2016-07-09
9 A 5, B 1, C 8, D 7, E 3, F 9, G 6, H 2, I 4
It is important to remember that the DDL must come before the DML. A table cannot be altered until it has
been created. The ALTER TABLE commands could be switched round. Inserting data into a table is the first
stage of DML. The query command would only be used once the database was created and the data inserted.
Note that this assumes that the materials needed for a task do not depend on which contract they are to
be used on. However, the operatives performing the tasks will be chosen for the task on a specific contact
and will not always be the same for different contracts.
e
Table Primary key Foreign key
Customer CustomerID
Contract ContractID
ContractID
Contract-Task ContractID+TaskID
TaskID
Task TaskID
TaskID
Task-Material TaskID+MaterialID
MaterialID
Material MaterialID
ContractID+TaskID
Contract-Task-Operative ContractID+TaskID+OperativeID
OperativeID
Operative OperativeID