Database Systems Exam Summary - UHBC June 2021
General Exam Information
- Course: Database (Bases de données) - L2
- Institution: UHBC (Université Hassiba Benbouali de Chlef)
- Instructor: Aridj med
- Date: June 2021
- Duration: 1 hour and 30 minutes
- Notes: Forbidden documents.
Exercise 1: Conceptual and Logical Modeling for a Media Library
Specification of Needs
- A disc is identified by an and consists of a set of tracks (plages).
- Each track contains exactly one work (œuvre).
- One work can span several tracks (for example, a symphony in 4 movements).
- For each track, the performers (interprètes) are known.
Logical Model (MLD)
Based on the requirements, the following logical model is deduced:
- Client Relationship (Work):
- Interpreter Relationship (Performer):
- Track Relationship:
- Disc Relationship: \text{Disque }(\text{IDD, Date_p})
- Performance Relationship:
Key Identifiers and Constraints
- Composite Key: in the relationship .
- Foreign Keys: and in the relationship .
Exercise 2: Relational Data Analysis and Synthesis Algorithm
Hotel Relation Characteristics
The provided relation "Hôtel" contains the following columns and data:
- Columns: (), (), (), (), ().
| IdHotel (A) | NumChambre (B) | TypeChambre (C) | CatégorieHotel (D) | Prix (E) |
|---|---|---|---|---|
| 1 | 100 | 1 | 2 | 50 |
| 4 | 101 | 3 | 2 | 50 |
| 1 | 102 | 2 | 2 | 70 |
| 1 | 200 | 1 | 2 | 50 |
| 2 | 101 | 3 | 3 | 100 |
| 2 | 200 | 1 | 3 | 70 |
| 3 | 100 | 1 | 2 | 50 |
Definitions and Metrics
- Rows (Linges): Represent tuples, items, or records.
- Columns: Represent attributes, properties, or fields.
- Degree: The number of columns in the relation. Degree = .
- Cardinality: The number of tuples in the relation. Cardinality = .
Functional Dependencies
Based on the data, the set of non-trivial functional dependencies is:
- Candidate Keys:
- Closure of F:
Synthesis Algorithm (Iterative Process)
- Iteration 1:
- Step 1: Start with .
- Step 3: No isolated attributes found.
- Step 4.1: Determinant .
- Step 5.1: Dependent .
- Step 6.1: Resulting relation .
- Iteration 2:
- Step 4.2: Determinant .
- Step 5.2: Dependent .
- Step 6.2: Resulting relation .
- Iteration 3:
- Step 4.3: Determinant .
- Step 5.3: Dependent .
- Step 6.3: Resulting relation .
Final Relational Schema:
Exercise 3: Bank Database (Relational Algebra and SQL)
Database Schema (BANQUE)
- AGENCE: \text{(Num_Agence, Nom, Ville, Actif)}
- COMPTE: \text{(Num_Compte, Num_Agence, Num_Client, Solde)}
- CLIENT: \text{(Num_Client, Nom, Prenom, Ville)}
- EMPRUNT: \text{(Num_Emprunt, Num_Agence, Num_Client, Montant)}
Query R1: Clients who have never taken out a loan
Relational Algebra Approach:
- R_a \leftarrow \text{proj}(\text{CLIENT, Num_Client})
- R_b \leftarrow \text{proj}(\text{EMPRUNT, Num_Client})
Query R2: Clients with an account in all agencies
Relational Algebra Approach:
- R_a \leftarrow \text{proj}(\text{AGENCE, Num_Agence})
- (Division operation to find clients with accounts in all agencies)
- R_c \leftarrow \text{join}(R_b, \text{CLIENT, } R_b.\text{Num_client} = \text{CLIENT.Num_client})
Query R3: Number of clients with an account in an agency located in their own city
SQL Approach:
SELECT COUNT(DISTINCT Num_client)
FROM COMPTE, AGENCE, CLIENT
WHERE (COMPTE.Num_client = CLIENT.Num_client)
AND (COMPTE.Num_agence = AGENCE.Num_agence)
AND (CLIENT.Ville = AGENCE.Ville);
Query R4: Number of agencies per city
SQL Approach:
SELECT COUNT(Num_agence)
FROM AGENCE
GROUP BY Ville;
Query R5: Result Interpretation
SQL Code:
SELECT Num_Client
FROM Compte
WHERE Solde > (SELECT SUM(Actif) FROM Agence WHERE Ville = 'Chlef');
Result Interpretation: This query returns the list of customer numbers (\text{Num_Client}) who have a balance () strictly greater than the total sum of assets () of all agencies located in the city of Chlef.