Tutorial 2
Tutorial 2
Exercise 1:
1. Consider the following person class:
a. Define all necessary types required to create the TPerson type.
b. Implement a method to calculate a person's age.
c. Create the Person table based on the TPerson type.
d. Insert a new person into the table with the following details:
■ SSN: 123456789
■ Name: Mohamed ADIMI
■ Birth_date: 01/01/1980
■ Address: 22 rue de la Gare, 16000 Algiers, Algeria
■ Phone Numbers: 0622233366, 0533666777
2. The Person class serves as the base class, from which two subclasses, Teacher and
Student, are derived as follows:
a. Create the TCourse and TAssessment types, ensuring that all associations and
their effects on existing types are properly considered.
b. Create the Course and Assessment tables based on the defined types.
1. Define the TFederation type, which includes a name and a collection of member
countries.
2. Create the Country and Federation tables to store instances of TCountry and
TFederation, respectively.
3. Execute the following insert operations:
USTHB 3rd Year of Computer Engineering
Computer Science Faculty Module: A-DB
2024/2025
a. Add the country Algeria, with Algiers as its capital, Bordj el-Kiffan as one of its
main cities. This city has a population of 620,000.
b. Insert the city Bab el-Oued within Algeria, with a population of 900,000.
c. Add Annaba to the list of Algeria’s main cities.
d. Insert the country Tunisia, with Tunis as its capital, a population of 10,000,000, and
a 620 km border with Algeria.
e. Create the AT Federation, comprising Algeria and Tunisia.
4. Write SQL3 queries to:
1. Compute the total border length for each country.
2. Retrieve the names and capitals of all countries bordering Tunisia.
3. List the main cities of all member countries in the AT Federation.
Exercise 3: Consider the following relational database, modeling books (primary keys are
underlined):
Relation Description
4. We aim to store a list of phone numbers for each author in the database. Each phone
number should be associated with a label specifying its type (e.g., mobile, office, home).
Write the necessary SQL3 queries to insert and manage this information in the database.
5. We enhance the Author type by adding the MyBooks method, which returns a set of
books where the author is listed as the first author (rank = 1), ensuring no duplicates.