Converting the Diagram to a Specific Language Query
For simpler queries, the following advice works.
Where you need set operations or division, a little more thought is needed.
- Relational Algebra: we'll do a correct but not necessarily optimal
query.
- Do an appropriate combination of Cartesian products and
natural joins of the relations required.
- Do a select where the predicate demands that all the links and
constants in your diagram be true.
- Don't forget that natural joins will take care of some of your
diagram's links.
- Finally, do a project of the attributes to be printed out.
- Tuple Relational Calculus:
- Create a tuple variable for each of the relations in your diagram.
- Make sure the parentheses give you the required scope.
- Ensure each link and constant in your diagram corresponds to some
part of your predicate.
- Make sure t gets the attributes that should be printed out.
- Domain Relational Calculus:
- Create domain variables. Name them sensibly.
- Remember that equality is forced by using the same domain variable
in several places.
- Other comparison operators may be explicitly stated, e.g. .
- Remember to use the existential qualifier for domain variables, and
to make sure your scoping is correct.
- SQL: similar to relational algebra.
- Put all the relations needed in the from clause.
- Remember to use tuple variables when you have more than one copy
of a relation, or for general convenience.
- Express each of the links and constants in your diagram as part of
the predicate in the where clause.
- State the attributes to be printed out in the select clause.
- QBE: your diagram is almost QBE to start with.
- Select the skeleton tables needed.
- Remember that you only need one skeleton table per relation.
You can put more than one line in a skeleton table.
- Force equality on links by using the same domain variables in
different places (see the connection to domain relational calculus?).
- Use the condition box where necessary.
- Use P. to print out the attributes.
Remember to use a result relation if attributes are printed out from
more than one skeleton table.
More complicated queries will take more thought, but I believe this
intermediate step of making a diagram is always helpful.