The DataBase Course
Exercise No. 3
SQL and Relational Calculus - Practical
Due on January 12th by midnight
The Example Database Schema: Animals participate in research projects, that may span several years and sites in many countries. Animals may participate in many projects, and may also be moved between sites during the same project. The children table keeps parenthood relations between animals, by keeping the animal id of each parent and child.
Animal(aid, species, weight, birthyear)
Children(parent, child)
Sites(sid, name, country, size, climate)
Research(rid, name, subject)
Events(aid, sid, rid, year)The aid, sid, rid attributes are key attributes. The tables are available to query using Oracle, after you have executed the file ~db/animals.sql (see the "SQL Basics" page in the homepage).
Express the following queries in safe tuple relational calculus and SQL:
- Which animals are younger than a12?
- Which projects whose subject is medicine are performed entirely in China?
- Which animals were born in a year during which no project was using Canada's eastern coral reef?
- Get all pairs of animal ids of animals that participate in the same project. Include only one of every (a,b) and (b,a) pair.
- For which species of animals there are animals that have joint children with more than one other animal?
- Name species in which animals never become parents before they are 20 years old.
- Name projects that moved an animal between different climates in consecutive years.
- Get project numbers of projects that use the same animal in all the sites.
- When (in which year) did the Rainforest Insects project start?
- What is the average age of the animals in the Golden Bear project? Only an SQL query is required for this query.
You should submit:
- The first nine queries in calculus, on paper.
- Printouts of the ten SQL queries and outputs, together with the calculus queries.
- Submit electronically (run ~db/bin/submit to submit ex1.tar) the following files:
README - containing only your login in the first line, and your full name and relevant exercise documentation afterwards.
queries.sql - containing the queries.
outputs.txt - containing the outputs.- Keep a photocopy of the relational calculus queries - you may need them for ex4.