0% found this document useful (0 votes)
3 views

Tutorial 2

The document outlines a tutorial for a 3rd Year Computer Engineering course focusing on database management. It includes exercises on defining types, creating tables, inserting data for persons, teachers, and students, as well as working with a relational database schema for books and authors. Additionally, it requires the implementation of SQL queries and methods for managing data in an object-relational DBMS.

Uploaded by

equipen6projet08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Tutorial 2

The document outlines a tutorial for a 3rd Year Computer Engineering course focusing on database management. It includes exercises on defining types, creating tables, inserting data for persons, teachers, and students, as well as working with a relational database schema for books and authors. Additionally, it requires the implementation of SQL queries and methods for managing data in an object-relational DBMS.

Uploaded by

equipen6projet08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

USTHB​ ​ ​ ​ ​ ​ ​ 3rd Year of Computer Engineering

Computer Science Faculty​ ​ ​ ​ ​ ​ Module: A-DB


2024/2025
Tutorial 2: OR DB

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.​ Define the Student and Teacher types.


b.​ Insert a new student with the following details:
■​ SSN: 123123123
■​ Name: Adam Merabeti
■​ Date of Birth: 01/05/1985
■​ Address: Didouche Mourad, Algiers, Algeria
■​ Phone Number: Not provided
■​ Student ID: 999
USTHB​ ​ ​ ​ ​ ​ ​ 3rd Year of Computer Engineering
Computer Science Faculty​ ​ ​ ​ ​ ​ Module: A-DB
2024/2025
■​ Department: Computer Science
■​ Degrees: None
c.​ Insert a new teacher with the following details:
■​ SSN: 666999666
■​ Name: Meriem Lamari
■​ Date of Birth: 04/06/1975
■​ Address: 99 Boulevard Colonel Amirouche, Algiers, Algeria
■​ Phone Number: Not provided
■​ Teacher ID: 777
■​ Bank Account: 310 111111 89 (BDL)
d.​ Insert another teacher with the following details:
■​ SSN: 556978566
■​ Name: Ahmed Salemi
■​ Date of Birth: 04/06/1965
■​ Address: 99 Ismail Yafsah, Algiers, Algeria
■​ Phone Number: Not provided
■​ Teacher ID: 787
■​ Bank Account: 330 1234897 56 (BEA)
e.​ Add phone numbers 022342222 and 066543333 for student Adam Merabeti.
f.​ Assign the same phone numbers to teacher Meriem Lamari.
g.​ List all students, displaying their names and student IDs.
h.​ Find pairs of people who share at least one phone number.
3.​ Let the final diagram be as follows:
USTHB​ ​ ​ ​ ​ ​ ​ 3rd Year of Computer Engineering
Computer Science Faculty​ ​ ​ ​ ​ ​ Module: A-DB
2024/2025

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.

Exercise 2: We consider the following SQL3 schema:

CREATE OR REPLACE TYPE TCountry ;


/
CREATE OR REPLACE TYPE TBorder as object (
country ref TCountry,
length NUMBER
);
/
CREATE OR REPLACE TYPE TSet_Borders as table of TBorder ;
/
CREATE OR REPLACE TYPE TCity as object (
name VARCHAR2(30),
country REF TCountry,
population number
);
/
CREATE OR REPLACE TYPE TSet_Ref_Cities as table of ref TCity;
/
CREATE OR REPLACE TYPE TCountry as object (
name VARCHAR2(30),
capital REF TCity,
main_Cities TSet_Ref_Cities,
population NUMBER,
limits TSet_Borders
);
/
CREATE OR REPLACE TYPE TSet_Ref_Countries as table of ref TCountry;​
/
CREATE TABLE Cities OF TCity;
INSERT INTO Cities VALUES ('Algiers', NULL, 2000000);
INSERT INTO Cities VALUES ('Annaba', NULL, 500000);
INSERT INTO Cities VALUES ('Blida', NULL, 1000000);

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

BOOK(ISBN,Title,Year,Language,PublisherID) ISBN: Unique identifier for the book.


Title: Name of the book.
Year: Publication year of the book.
Language: Language in which the book was
published (French, English, or Spanish).
Publisher ID: Identifier of the publisher
responsible for the book's publication.

AUTHOR (AuthorID, LastName, FirstName) AuthorID: Author’s identifier


LastName: Author's last name
First Name: Author's first name

COLLABORATION (ISBN, AuthorID, Rank) ISBN: Unique identifier of the book.​


AuthorID: Unique identifier of the author.​
Rank: Position of the author in the book's
author list (e.g., 1st author, 2nd author, etc.).

This relationship represents the collaboration


between authors in writing a book and
indicates each author's rank in the list of
contributors.

PUBLISHER (PublisherID, Name, Country) PublisherID: Unique identifier for the


publisher.
Name: Name of the publisher.
Country: Country where the publisher is
based.

1.​ Convert the given relational schema into a class diagram.​

2.​ Implement the class diagram in an object-relational DBMS using SQL3:​


a. Define the required object types, ensuring all relationships are properly modeled.​
b. Create the necessary tables to store the database.
3.​ The database includes authors David Fayon and Michaël Tartar, along with the publisher
Pearson.
USTHB​ ​ ​ ​ ​ ​ ​ 3rd Year of Computer Engineering
Computer Science Faculty​ ​ ​ ​ ​ ​ Module: A-DB
2024/2025
Write an SQL3 statement to insert the book titled "Digital Transformation 2.0" (ISBN:
978-2-7440-6709-9), published by Pearson in June 2019. The book is authored by David
Fayon (as the first author) and Michaël Tartar.

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.

Provide the method signature and its implementation.

You might also like