Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PostgreSQL Lab

2.021 – UAB – DACSO


Pere Pons
PostgreSQL Lab
The model that has been introduced in the lectures will be the basis
of the following lab exercises.

In the next page you will find the reminder of the specification
introduced by the client, and in the following pages you will find
different situations to face with the database.

You have to deliver a document with the solution to the exercises


before the deadline arrives. Work in groups of two.
Remider of the model.
Martian Empire is a company that exploits tourism in Mars.

Martian people have a Martian identifier that is unique. We store the


name, surname and email of people, and every Martian is assigned to a
base, except honorees exceptions. In each base we have some resorts to
spend some holiday, we keep track of everyone that visits our resorts and
store when did he arrive and how long the visitor stayed.

As we have to take care of our visitors, we control the stock of supplies at


resort level. Is to say, we know how many items we have in each resort,
and we control the cost of the stock assuming that all supplies have the
same const independently of the resort that owns it.

On the other hand, now we are only admitting Martian people, because
they are kinder than earthers, but we have created a marketing database
to store Earthers that may be interested in coming to Mars and providing
us more wealth for standing them.
Exercises
1. As a emergency plan support we need a list with names, surnames and name of the base
where the Martian is registered for all Martians in the database.
2. Make the shopping list for all resorts so that all of them have all known supplies (the ones
listed in the database) with a total of 25 units for each supply in each resort.
3. Prepare the TOP10 visitor list, with the names and surnames of the 10 Martians that have
spent more days in some resort, no matter which one.
4. Prepare a list with all Martians and the number of days spent in each resort.
5. Create a table to store the visits of Earthers to the Martian resorts. The table has to store the
date of the visit and the number of days spent in the resort.
Exercises
6. We want to have an email for each supply that identifies the supplier. The field can not be
null, and if we do not know the email we must write ‘no@mail.mars’. Please modify the
supplies table without loosing any existing data.
7. We must make sure that Earthers do not provide us with empty emails. Add the check
clause so that no empty emails are allowed.
8. Identify how PostgreSQL will plan the query: “Select email from martians where
surname=‘my_surname’”
9. Alter what you think that may improve the execution of the previous query. Demonstrate the
improvement.
10. Create a backup of the database with the tool pg_dump
Delivery

• You have to deliver a pdf document where you provide the solution
for the exercises.
• Stay alert for the deadline, the delivery will be closed automatically
when the period expires.

You might also like