DB1 2018 01 04 Solution
DB1 2018 01 04 Solution
This is a multiple-choice exam. Each question might have several correct choices, but you must select only
one choice. If you select more than one, your answer will be marked as incorrect (even if you have selected
only correct choices).
The questions are divided into four sections:
Section Questions
Data modeling 10
SQL 10
FDs, CKs, NFs and normalization 10
Other 6
Failing to meet any of these criteria means failing the exam (i. e. grade U).
If you fulfill both criteria, your grade will be determined by the number of correct answers:
Your answers must be given on the answer sheet which will be handed in. Don’t forget to fill out your exam
code. To mark your answer fill the answer box entirely using a dark colored pen (black or blue). The optical
character recognition system will not recognize ticks, crosses, circles or any other additional notes. Remember,
do not to fill more than one answer box per question.
If you make a mistake on the answer sheet, request a new one and make sure you hand in the correct sheet
(if you hand in several answer sheets, your exam will not be graded).
You can keep the question sheets. We recommend that you first note your answers on these and fill out the
answer sheet just before handing it in.
Allowed aids One A4 sheet with handwritten notes (both sides can be used) which must be handed in with
your exam (remember to fill out your exam code). An English explanatory dictionary and/or a translation
dictionary between English and your mother tongue.
Page 2
A IT
B STS
C X
D Other CS/math/physics
E Other non-CS/math/physics
Question ii (Not assessed.) In which period were you registered in the course for the first time?
Question iii (Not assessed.) How many lectures have you attended?
2 Data modeling
A Weak attribute
B Composite attribute
C Key attribute
D Derived attribute
E Composite multi-valued attribute
N N
E1 R E2
A No
B Yes
Page 3
Question 3 The Internet Movie Database (IMDb) is an online database of information related to movies.
Registered users can rate movies on a scale of 1 to 10 stars (each user can rate each movie once). Based on the
ratings IMDb shows the average rating as well as average ratings for different combinations of gender and age
(e. g. the average rating given by males between 18 and 29 years old) for each movie. Which of the following
ER diagrams shows a correct way how to store the ratings? (Only the relevant portion of each diagram is
shown.)
N N N N
User rates Movie User rates Movie
Id Id Id Id
A C
N N N N
User rates Movie User rates Movie
Id Rating Id Id Rating Id
B D
Question 4 In a medical experiment we give a patient an experimental drug and measure his or her blood
pressure 1, 6, 12 and 24 hours after taking the drug. These measurements must be stored in the database and
it must be possible to say which measurement was first, which second etc. Can the following model be used?
(Only the relevant portion of the diagram is shown.)
Id Patient Pressure
A Yes
B No
Question 5 Which of the following statements about the depicted ER diagram is correct?
1 N
E1 R E2
A Each E1 entity must be related to one or more E2 entities. An E2 entity can be related to zero or one E1
entity.
C Each E1 entity must be related to exactly one E2 entity but it can be related to it many times. An E2
entity can be related to zero or one E1 entity.
D An E1 entity can be related to zero, one or more E2 entities. Each E2 entity must be related to exactly
one E1 entity.
E An E1 entity can be related to zero or one E2 entity. Each E2 entity must be related to one or more E1
entities.
Page 4
Question 6 The ER diagram from the previous question is equivalent to which of the following diagrams?
Question 7 Based on the depicted ER diagram and the semantics of ER models, which of the following
statements is correct? (Hint: only one choice is correct.)
Name Name
N 1
City is in Country
Question 8 Convert the ER model from the previous question to a relational model.
C The ER model cannot be converted to a relational model because both City and Country have an attribute
with the same name.
Question 9 Consider the following ER model for a database of soccer games in the next season of Allsven-
skan (a Swedish professional soccer league). Convert the model to a relational model.
City
Id Coach
Team
Home Away
N N
plays
game
Date Score
Question 10 Which of the following relational models can be used for the ER model depicted below:
d
⊂
3 SQL
For questions 11 – 15 consider the following database consisting of two tables T1 and T2:
T1 T2
C1 C2 C1 C2
A 1 A 4
A 2 A 2
B 2 B 2
C 1 D 5
Question 11 How many rows are in the result of the following SQL query?
SELECT *
FROM T1, T2
Hint for the following 4 questions: First, write down the result of the following queries:
• SELECT T1.C1, T1.C2, T2.C1, T2.C2, T1.C2*T2.C2 FROM T1 JOIN T2 ON T1.C1 = T2.C1
• SELECT T1.C1, T1.C2, T2.C1, T2.C2 FROM T1 LEFT JOIN T2 ON T1.C1 = T2.C1
Question 12 What is the result of the following SQL query? (Not showing the header of the result.)
A 2 A 2 C Empty table
A 2 A 4
A A 2 A 2
B 2 A 4
B 2 B 2 D A 2 A 4
B 2 B 2
A 1 A 4
A 2 A 4 A 2 A 2
E
B A 1 A 2 A 2 A 4
A 2 A 2
B 2 B 2
Page 7
Question 13 What is the result of the following SQL query? (Not showing the header of the result.)
A SQL is invalid A 8
C
B 4
D A 22
A 18
B
B 4 E A 12
Question 14 What is the result of the following SQL query? (Not showing the header of the result.)
A A 22 D A 12
C A 18
Question 15 What is the result of the following SQL query? (Not showing the header of the result.)
1 2 1 2
C
1 4 1 4
A
1 NULL
NULL 5 D NULL 5
1 2 E Empty table
B 1 4
1 NULL
Page 8
For questions 16 – 20 consider a set of data organized in a hierarchical tree structure. A tree can be defined as
a collection of nodes, where each node consists of data and the reference to its parent node. A node can be a
parent for many nodes, these nodes are called children of that node. Each non-empty tree has one node without
any parent, such a node is called the root. Nodes without any children are called leaves. (There are also some
additional constraints but these are not relevant for these questions.)
To represent such a hierarchical tree structure, we will use the following relation:
Node(id, data, parent id)
Question 16 Assume that data is a short string. What is the correct SQL to create the Node table?
A CREATE TABLE Node(id int NOT NULL PRIMARY KEY, data varchar(255),
parent id int, FOREIGN KEY(id) REFERENCES Node(parent id))
C CREATE TABLE Node(id int NOT NULL PRIMARY KEY, data varchar(255),
parent id int NOT NULL, FOREIGN KEY(id) REFERENCES SELF)
D CREATE TABLE Node(id int NOT NULL PRIMARY KEY, data varchar(255),
parent id int REFERENCES SELF)
E CREATE TABLE Node(id int NOT NULL PRIMARY KEY, data varchar(255),
parent id int, FOREIGN KEY(parent id) REFERENCES Node(id))
Question 17 Finish the SQL query to select the ID and the data of the root:
SELECT À
FROM Node
WHERE Á
Question 18 Finish the SQL query to select the ID and the data of the leaves:
Question 19 Finish the SQL query to select the ID and the data of all grandchildren (i. e. children of
children) of the node with the ID 123:
SELECT À
FROM node n, node m
WHERE Á
Question 20 Finish the query to select the ID and the children count for each node:
A False
B parent id IS NOT NULL
C None of the other answers
D id != NULL
E True
Question 24 Which of the following normalized databases contains all the information contained in the
original table, with all relations in BCNF (not showing the foreign key constraints)?
For questions 25 – 28, consider a relation in 1NF R(A, B, C, D, E) with the following dependencies:
• {A, B} → {C}
• {B} → {E}
• {E} → {D}
Question 25 What is {B, C}+ (i. e. the set of all attributes which can be determined by {B, C})?
A {B, C, D, E}
B Empty set
C None of the other answers
D {B, C, E}
E {A, B, C, D, E}
F {B, C}
A {A, B, E}
B {A, B} and {E}
C {A, B}
D All sets including both A and B
E There are no candidate keys
F {A, B, C, D, E}
Question 27 In which NF is R?
Question 28 Which of the following normalized databases contains all the information contained in the
original table, with all relations in BCNF (not showing the primary and foreign key constraints)?
Question 29 The following table shows the current state of a relation. Is it true that {C2 } → {C3 }?
C1 C2 C3 C4
1 1 XX 157
2 1 XX 178
3 1 XX 192
4 2 XY 183
5 2 XY 166
Question 30 Consider a relation R(A, B, C, D) in 1NF, with two candidate keys {A} and {B}. Which of
the following statements is correct? (Assume that no attribute can be determined by the empty set.)
A R is in BCNF
B R is at least in 3NF
C R is not in 2NF
D R is in 3NF
E R is at least in 2NF
5 Other
Question 31 In the relational model, if K is a candidate key of relation R and X is one of its attributes (i. e.
X ∈ K), then:
Question 33 When transferring money from one bank account to another we need to run two SQL state-
ments, one that reduces the balance of the first account and one that increases the balance of the second account.
Which of the ACID properties guarantees that either both SQL statements get executed (and the money is trans-
ferred) or none does (not transferring the money at all)?
A Atomicity
B Isolation
C Durability
D Consistency
E Integrity
A Superkey
B Primary key
C Foreign key
D Determinant
E Candidate key
Question 35 Bob creates the table X. Then, the following sequence of statements is executed, in the given
order (the name of the user executing the statement is indicated at the beginning of each statement):
Bob: GRANT SELECT ON X TO Jim WITH GRANT OPTION
Bob: GRANT SELECT, UPDATE ON X TO Ann WITH GRANT OPTION
Jim: GRANT SELECT ON X TO Tim
Ann: GRANT SELECT ON X TO Tim
Jim: REVOKE SELECT ON X FROM Tim
Which privileges (concerning the table X) does Tim have?
Question 36 Consider a relation R(A, B, C, D) containing 107 records. A is the primary key, and B
contains 105 distinct values. The following prepared statement is executed very frequently:
SELECT C FROM R WHERE B=?
Which index would help to avoid the full table scan?
A One index on B
B One index on (B, C)
C One index on C
D One index on (C, B)
E One index on A and one on C
y +1/15/46+ y
i A: B: C: D: E: 18 A: B: C: D: E:
ii A: B: C: 19 A: B: C: D: E:
iii A: B: C: D: E: 20 A: B: C: D: E:
1 A: B: C: D: E: 21 A: B: C: D: E:
2 A: B: 22 A: B: C: D: E:
3 A: B: C: D: 23 A: B: C: D: E:
4 A: B: 24 A: B: C: D: E:
5 A: B: C: D: E: 25 A: B: C: D: E: F:
6 A: B: C: D: 26 A: B: C: D: E: F:
7 A: B: C: D: E: 27 A: B: C: D: E: F:
8 A: B: C: D: E: 28 A: B: C: D: E:
9 A: B: C: D: E: 29 A: B: C:
10 A: B: C: D: E: 30 A: B: C: D: E:
11 A: B: C: D: E: 31 A: B: C: D: E:
12 A: B: C: D: E: 32 A: B: C: D: E:
13 A: B: C: D: E: 33 A: B: C: D: E:
14 A: B: C: D: E: 34 A: B: C: D: E:
15 A: B: C: D: E: 35 A: B: C: D: E:
16 A: B: C: D: E: 36 A: B: C: D: E:
17 A: B: C: D: E:
y y