You are on page 1of 5

Université Libanaise Date : 03/03/2022 Semestre : 1

ISSAE - Cnam Liban Durée : 120 min Année : 2021-2022


Centre du Liban associé au Cnam De 13h00 à 15h :00
Paris

Code UE : NFA008
Ce sujet comporte : 5 pages
Intitule de l’UE : Base de données (English version)

 Semestriel  Partiel ◼ Final  Rattrapage


Type d’examen :
 Annuel  E1  E’1  E2  E’2
Documents autorisés :  Tous ◼ Aucun  Autre (A préciser : ………………………………………..)
Consignes particulières : ……………………………………………………………..

Calculatrice: ◼ Aucune  Programmable  Non programmable

◼ Beyrouth  Baakline ◼ Baalbeck


Centres concernés ◼ Nahr Ibrahim
◼ Bickfaya ◼ Chtaura ◼ Tripoli

Question 1 ER diagram 4 pts

Read the text below and trace the corresponding ER diagram:

In an enterprise, we would like to represent the personal and their affectation. Each employee
is affected to a service. Each service is described by its name; its leader who is necessarily
affected to the service and the list of the service premises. The personal is of 3 categories: admin,
technicians and managers.

Each employee has an employee number, a first name, a last name, an address, a salary and a
banking identification defined by: name of the bank, name of the agent and an account number.

Additional information is set by category as follow:


 Admin and technicians have an hourly rate
 Each admin should report to a manager
 Each technician has is a list of machines that are under his responsibility
 Each manager has an office, a phone extension number and the list of admin employees
that report to him
Question 2 SQL-Multiple parts 6 pts

Consider the following Hospital database schema with 7 relations.

Patient
pid name age address
Doctor
did name Department_id Specialty
Doc_availability

Admission
pid did roomNumber Admission_Date Duration_of_stay
Department

Nurse
nid name Department_id
Room
roomNumber Department_id capacity CostPerDay

Notes:
• The duration of stay in table Admission is in Days.
• A nurse can work for more than 1 department.
• The capacity in Room= the number of beds inside the room
Part 1- Choose the correct answer. (4 pts)

1.1) Give all the pid and names of patients who live in Beirut
a) SELECT PID, NAME FROM PATIENT HAVING ADDRESS=’BEIRUT’
b) SELECT PID, NAME FROM PATIENT WHERE ADDRESS EXISTS ‘BEIRUT’
c) SELECT PID, NAME FROM PATIENT WHERE ADDRESS= ’BEIRUT’
d) SELECT PID, NAME, ADDRESS=’BEIRUT’ FROM PATIENT

1.2) How many doctors work in the hospital?


a) SELECT COUNT(DID) FROM DOCTOR
b) SELECT SUM(DID) FROM DOCTOR
c) SELECT COUNT(NAME) FROM DOCTOR
d) SELECT COUNT(NAME) FROM DOCTOR GROUP BY NAME

1.3) Which department (id) has the maximum number of nurses?


a) SELECT MAX(NID) FROM NURSE
b) SELECT COUNT(NID) FROM NURSE
c) SELECT MAX(NID) FROM NURSE GROUP BY DEPARTMENT_ID
d) None of the above
1.4) Give all the doctor names who work in the Maternity department.
a) SELECT NAME FROM DOCTOR WHERE DEPARTMENT_ID=’MATERNITY’
b) SELECT NAME FROM DOCTOR NATURAL JOIN DEPARTMENT WHERE
DEPARTMENT_NAME = ’MATERNITY’
c) SELECT NAME FROM DOCTOR WHERE DEPARTMENT_ID= (SELECT DEPARTMENT_ID
FROM DEPARTMENT WHERE DEPARTMENT_NAME=’MATERNITY’)
d) Both b and c

1.5) Which patient(s) have stayed the longest in the hospital?


a) SELECT PID,Duration_of_stay FROM ADMISSION where
Duration_of_stay = (select max(Duration_of_stay) from admission)
b) SELECT PID,Duration_of_stay FROM ADMISSION WHERE Duration_of_stay=MAX()
c) SELECT PID,COUNT(Duration_of_stay) FROM ADMISSION
d) All of the above

1.6) To which department is the patient “Karim Asmar” admitted to?


a) SELECT DEPARTMENT_ID FROM PATIENT, ADMISSION, ROOM WHERE
NAME=’KARIM ASMAR’
b) SELECT DEPARTMENT_ID FROM PATIENT NATURAL JOIN ADMISSION NATURAL
JOIN ROOM WHERE NAME=’KARIM ASMAR’
c) both a and b work
d) Neither a nor b work

1.7) Output the departments who have more than 10 nurses.


a) SELECT DEPARTMENT_ID FROM NURSE GROUP BY DEPARTMENT_ID HAVING
MAX(NID)=10
b) SELECT DEPARTMENT_ID FROM NURSE GROUP BY DEPARTMENT_ID HAVING
COUNT(NID)>10
c) SELECT DEPARTMENT_ID FROM NURSE GROUP BY NID HAVING COUNT(NID)>10
d) SELECT NID FROM NURSE GROUP BY NID HAVING COUNT(NID)>10

1.8) Give all the names of the doctors and their IDs for those are specialized in
anykind of cancer. For example, breast cancer, colon cancer… and so on.
a) SELECT NAME, DID FROM DOCTOR WHERE SPECIALTY = ‘CANCER’
b) SELECT NAME, DID FROM DOCTOR WHERE SPECIALTY LIKE ‘CANCER’
c) SELECT NAME, DID FROM DOCTOR WHERE SPECIALTY = ‘%CANCER%’
d) SELECT NAME, DID FROM DOCTOR WHERE SPECIALTY LIKE ‘%CANCER%’

Part 2- Write the corresponding SQL statement to create the tables Departments and Doctor.
Don’t forget the primary keys and foreign keys constraints.

All foreign key constraints are set to reject any violations. (2 pts)
Question 3 Functional dependencies and Normalization 5 pts

Part A (1 pt)
Consider the table T (A, B, C, D, E, F) and the function dependencies:

A→ B,C
C→ D
D → E
F→ E

A.1) Compute the closure {A}+


A.2) What’s a good primary key for table T? Explain.

Part B (4 pts)
Consider the table Student with 5 attributes.
ID name age Course_code Course_name
516 Sara Najem 19 CS375 Database
516 Sara Najem 19 CS310L Software lab
600 Ali Sayed 21 CS375 Database
600 Ali Sayed 21 CS10L Software lab
600 Ali Sayed 21 CS300 Logic design

B.1) Which is the right primary key: ID or (ID, course_code)? Explain


B.2) What are the FDs that hold in the above table?
B.3) Is this table in 1NF? Explain
B.4) Is this table is 2NF? Explain why or why not. In case it’s not, convert it.

Question 4 Relational Algebra 5 pts

Consider the following database :


Course_day(IdCourse, Day, Hour)
Course_room (IdCourse, IdRoom)
Student (IdStudent, Name)
Course_Student (IdCourse, IdStudent, Grade)

An example of possible common values for the database is shown below.


Course_day Course_Student

IdCourse Day Hour IdCourse IdStudent Grade


Architecture Monday 9h Architecture 100 A
Architecture 300 A
Algorithm Tuesday 9h
System 100 B
Algorithm Friday 9h
System 200 A
System Tuesday 14h
System 300 B
Algorithm 100 C
Algorithm 200 A
Course_room
Student
IdCourse IdRoom IdStudent Name
Architecture S1 100 Diala
Algorithm S2 200 Rami
Systen S1 300 Jad

A. Give the results of the following algebraic expressions: (2 pts)


1) R2 =  (IdCourse = ’ Algorithm’). Course_Student
2) R3 = π (IdStudent, IdCourse) Course_Student ÷ π (IdCourse) Course_day

B. Express the queries below in algebraic language (3 pts)

1) Give the names of the students taking the ‘System’ course


2) Give the pairs (day, time) for which room 'S2' is occupied by a Course.
3) List the names of students who are not enrolled in certain courses

Good Luck

You might also like