Semestral project DEMO
A "Zoo in a slide"
Warning:
Content was copied from a separate git repository. Eventual changes made here should be replicated to the source as well.
1. Description
The company "Zoo in a slide" is engaged in breeding various animals that can have a name and we can know their date of birth.
If the animal is lucky, it can become the godfather of a well-known personality (celebrity) for which it is essential to know the name, surname and date of birth, so that we do not get the personalities mixed up.
Celebrities can be invited to VIP feedings, where our zoo tries to psychologically push them to promote the zoo with the participation of the media.
Of course, the animals in our zoo are fed not only at VIP feedings, but also when visitors are present - that is, at assisted feedings, where we are mainly interested in the capacity of the persons so as not to attract too many visitors for PR, and also in the name. However, the zoo does not keep track of which visitor participated in the feeding. The zoo records many other types of feedings, but does not track further details for these as it does for assisted and VIP; however, the manager commented along the lines of considering night feedings in the future, but has not yet specified details.
What is important, however, is that for feeding, the food used for feeding should also be recorded. For simplicity, it was agreed that there is only one feed per feeding - so we do not expect to record mixtures of feeds.
Each feeding is carried out by a keeper. The keeeper is an employee and we must always know the personal number of the employee, which is the same throughout his employment and there is no case where two employees have the same number. We also need to know his address in which we must not forget the country. The essential information for an employee is his salary. For simplicity we record this information as the current salary, other things with the salary are already handled by the accountant outside our database. Every employee may have subordinates, however, there are also those who do not have subordinates and do not have supervisors - for example, the director of external relations, nobody talks to him, so he works alone in his workplace. However, we are only interested in employees in different roles, but we only deal with keepers and doctors as further links to our zoo database. However, it may be that an employee is both a doctor and a keeper at the same time, but may hold neither of these roles.
For a doctor, we record the doctor’s specialty, which is the best indication of his or her skills. A doctor may examine or assist in the examination of an animal. Occasionally, but rarely, a doctor will implement one measure for a given animal during an examination.
To work well with animals, it is also necessary to know their species and their current cage location in the section. The zoo has several sections and numbers the cages systematically from 1 to n. Thus, if someone asks for directions to the elephant enclosure, it is sufficient to tell the customer that he is in cage one in the savannah, or if he wants to go to the toad enclosure, he wants to go to the wetlands in cage one.
Since this is a zoo, it is good to know how much was collected in admission fees, so we still keep track of tickets for the cashier’s purposes. For tickets we are only interested in the price and the day it was sold.
2. ER schema
Not all entitities are in detail discussed in description above. Usually, during the database design there appear the necessity to include other aspects of the domain.

2.1. Loops discussion
There are loops in the diagram. List of loops below including explanation of possible problems.
Employee-Employee Loop: This is a parent-child relationship that can cause two problems:
- An employee can be his own superior. We don’t want that, that’s why we introduced IO1.
- An employee may be the superior of someone who acts as a superior to the given employee. We don’t want that either, but we will resign from this IO, we would have to write a trigger that would check this.
Feeding-Keeper-Employee-Doctor-Examination-Animal-Feeding loop: This is a loop that can cause a situation where an employee examined or assisted in the examination of an animal that is also fed (or vice versa, that is not fed). This is not a problem as these are different links that are unrelated. The situation would be different if we allowed assistance only to keepers. But this is not the case in our zoo, which is why everything is fine here.
Doctor-Examination-Doctor loop: This is a loop between the examination, the examining doctor and the doctor who provides the assistance. Here, there may be a problem that we would allow the same doctor to examine and assist at the same time. We don’t want to let this happen, which is why we introduced IO2.
Animal-Feeding-Vip-Celebrity-Animal loop: This is a loop where there can be a celebrity that acts as a godfather to an animal that has never been present for a VIP feeding (or, conversely, has been present). This is correct, as it does not matter whether she acts as the godfather of the animal and was present at the feeding or not. However, if a celebrity had to be present at the feeding to be a godfather, the database would require a different design.
More loops could be found in the diagram. However, logically, these are the above-mentioned problems that have been explained, or IO has been added to the scheme.
3. relational model
Somebody may prefer to see vizualized relational model instead of ER. Let us note, it includes foreign keys.

4. SQL scripts
Here we provide just links to create and insert scripts. If you want to experiment (in SQL), we recommend to create a standalone schema in your PostgreSQL database like this.
-- if the schema already exists, we can drop it (including content):
drop schema zoo_en cascade;
-- create a new empty one
create schema zoo_en;
-- switch default schema to zoo_en:
set search_path=zoo_en;
-- check if you are relly on zoo_en:
select current_schema();
-- run create script:
\i create-zoo.sql
-- run insert script:
\i insert-zoo.sql4.1. create script
4.2. insert script
5. Queries
- SQL statements
- RA queries
6. Conclussions
I spent a lot of time on the term paper, and with hindsight I can responsibly say that its scope is excessive. I would never again choose more than 13 entities, because even on them I would be able to implement all queries without problems.
Relational Algebra wasn’t so bad as I could try it in portal. Overall, the portal made my job work fine - except that the portal can’t recognize the same RA and SQL results, only if they are sorted differently.
Furthermore, it would be appropriate to provide more instructions, for example how to work with sequences, when it is practically only mentioned in the sample term paper you are reading.
However, even though it wasn’t my first database project, I learned something and I’m glad I did.
7. References
7.1. Special thanks
- Hostomice Brewery (in Czech)
8. Apendix
8.1. Table of SQL type categories
- DBS Portal requires to cover all SQL categories in your database semestral project.
- Table bellow provides a mapping of our SQL queries to required categories (without category explanation, it is in the portal)
| Category | Queries |
|---|---|
| A | Q2, Q4, Q7, Q8, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q21, Q22, Q23, Q24, Q25, Q26 |
| AR | Q2, Q4, Q7, Q8, Q23, Q25, Q26 |
| B | Q1 |
| C | Q3 |
| D1 | Q4 |
| D2 | Q5 |
| D2N | Q5, Q6 |
| D2R | Q6 |
| F1 | Q2, Q3, Q8, Q10, Q13, Q14, Q21, Q22 |
| F1R | Q2, Q3, Q8 |
| F2 | Q2, Q4, Q7, Q11, Q12, Q15, Q21, Q22, Q23, Q25,Q26 |
| F2R | Q2, Q4, Q7, Q23, Q25, Q26 |
| F3 | Q4, Q12, Q17 |
| F3R | Q4 |
| F4 | Q13, Q14, Q15, Q16, Q24 |
| F5 | Q16 |
| G1 | Q1, Q4, Q5, Q10, Q18, Q19, Q20, Q22 |
| G1R | Q1, Q4 |
| G2 | Q5, Q11, Q17 |
| G3 | Q13 |
| G4 | Q1, Q4, Q10, Q18, Q19 |
| G4R | Q1, Q4 |
| H1 | Q8 |
| H2 | Q3, Q4, Q5, Q7, Q8 |
| H2R | Q3, Q4, Q7, Q8 |
| H3 | Q8 |
| I1 | Q4, Q5, Q9, Q12, Q13, Q14, Q15, Q17, Q20, Q21 |
| I1R | Q4 |
| I2 | Q5, Q13, Q14, Q15, Q21 |
| J | Q4, Q10 |
| JR | Q4 |
| K | Q21 |
| L | Q18 |
| M | Q19 |
| N | Q17 |
| O | Q22 |
| P | Q20 |