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

SQL Tutorial

The document describes two SQL exercises. The first exercise involves creating a database called "my_booking" to store hotel booking information. It includes creating tables for clients, hotels, and bookings, and inserting sample data. The second exercise involves creating tables for a genealogical tree database with tables for people and their relationships. It provides questions to create and populate the tables, as well as queries to retrieve specific data.

Uploaded by

yasmine fk
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)
70 views

SQL Tutorial

The document describes two SQL exercises. The first exercise involves creating a database called "my_booking" to store hotel booking information. It includes creating tables for clients, hotels, and bookings, and inserting sample data. The second exercise involves creating tables for a genealogical tree database with tables for people and their relationships. It provides questions to create and populate the tables, as well as queries to retrieve specific data.

Uploaded by

yasmine fk
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/ 4

TUNIS BUSINESS SCHOOL

UNIVERSITY OF TUNIS

Tutorial 4 : SQL (DDL – DML)

Exercise 1:

Goal : Create and manage a database (DB) for hotel booking named “my_booking”.

Relational schema of the DB

The database “Booking” has the following relational schema:

Client (id_clt, name_clt, fname_clt, address_clt, phone_clt);

Hotel (id_h, name_h,nb_star,city_h);

Booking (id_b, #id_clt, #id_h, date_b, date_checkin, date_checkout, room, type, price);

Note: id_b is an artificial primary key in the table booking (auto increment).

Write the appropriate SQL queries neededto:

1) Create the DB “my_booking”.


2) Create the tables “Hotel”, “Client” and “Booking” defined as following:

Table Hotel

Table Client

CS120 1
TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

Table Booking

3) Give the appropriate statement to insert data of one row for each table

CS120 2
TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

4) Queries
a. Display the hotels of “Hammamet” and their categories.
b. Display the 5 stars hotels of “Djerba”.
c. Display the clients that have booked in the three star hotels of “Hammamet”.
d. Display the clients who have booked during the period of “01/07/2012” and
“22/08/2012”.
e. Display the clients living in “Tunis” and have booked in “Mahdia” hotels.
f. Display number of booking per hotel.
g. Display the total amount of booking per hotel.
h. Display the total amount of booking per city.
i. Display the total amount of booking per category.
j. Display the total amount of booking per room’s type.

Exercise 2:
Consider the following database schema GENEALOGICAL TREE:

PERSON (PersonNum, Last_name, First_name, #Numfather, #NumMother, gender)

UNIONS (#Num_husband, #NumWife )

Notice that the father, mother, husband and wife are persons.

Part 1 (DDL)

Question1: Create using SQL command the table “PERSON”.

Question2: Create using SQL command the table “UNIONS”.

Question3: Give the SQL command allowing you to add the "WeddingDate" field of the Date type to
the UNIONS table. This table becomes:

UNIONS (#Num_husband, #NumWife, WeddingDate )

Question4: From the following figure, give the appropriate statement to insert data of two Persons
and a weeding link of your choice.

CS120 3
TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

Part 2 (DML)

Express the following queries in SQL:

Question1: Change the first name of person number 3 to "AbdelKarim" instead of his current first
name "Karim"?

Question2: Who are the children of Person number ‘9’?

Question3: What is the first name of the wife of Person number 9?

Question4: How many daughters does Person number 9 have?

Question5: Display the first name and the last name of persons how has married between
10/10/2000 and 10/10/2020.

CS120 4

You might also like