04 PostgreSQL Lab Exercises
04 PostgreSQL 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.
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 ‘[email protected]’. 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.