Professional Documents
Culture Documents
EM6043 20191218 A With Solutions
EM6043 20191218 A With Solutions
This is the first part of the exam and should be returned within 30 minutes.
If table A has 7 rows and table B has 5 rows, any cartesian product between A and B would produce:
1 at most 13 rows
2 exactly 13 rows
3 at most 35 rows
! exactly 35 rows
The NULL value:
1 Can appear only one time in a table
! Can be used for attributes whose value is unknown
2 Can’t be used in tables
3 Can’t be used in queries
1 Is always single attribute of a relation and must be unique within such relation
2 Is always single attribute of a relation and must be unique within all the relations in the database
! Can include more than one attribute of a relation and must be unique within such relation
3 Can include more than one attribute of a relation and must be unique within all the relations in the database
1
2 SQL Language questions (2 points each)
A database used to model a e-commerce website is made up of the following tables:
userid name city userid prodid quantity
prodid description price
101 ”Mario Rossi” Milan 101 11 1
10 TV LCD Samsung 450.0
102 ”Giovanni Verdi” Venice 101 12 2
11 LCD TV LG 400.0
103 ”John Smith” Milano 102 10 2
12 HDMI cable 10.90
104 ”Piero Boscolo” Chioggia 103 12 10
products users basket
For each of the following queries write the output table (using the space below each query):
SELECT count(price) AS total FROM products, users, basket
total
48
SELECT p.description FROM basket AS b, products AS p WHERE p.prodid=b.prodid AND p.price<500
description
TV LCD Samsung
HDMI cable
LCD TV LG
HDMI cable
SELECT a.description FROM products AS a, products AS b WHERE a.price=50+b.price
description
TV LCD Samsung
2
Student Name Student ID Teamwork (yes/no) Groupname
Use a E/R diagram to model the described scenario and translate it to suitable relation schemas.
Write down as additional notes all the information that you think could be useful to better describe the solution. The
student must submit this second part within 60 minutes.
The dean of your University asks you to design a database to store data about courses and exams. He lets you complete
freedom, however he strictly requires that the following data can be extracted from the database using one or more
queries:
• Given an exam, find all the exams that must be passed before attempting it
• Given an exam and a year, find the average mark obtained by all the students that passed the exam that year
• Given an exam and a student ID, find how many times (if any) the student failed the exam
• Given an exam and a city, find the average mark obtained for that exam by students from that city
Note that you are not required to write the queries to extract such data ! However an expert CIO must be able to
write them. Thus you have to check that the critical questions can be answered using your data organization.
Exams(examId, description)
Students(studentId, name, city)
comesBefore(mustBePassedExamId, toAttemptExamId)
hasAttempted(attemptedExamId, attemptingStudentId, date, grade, accepted)