Query Languages - Chapter 6

1.	Relational Algebra
	Express queries by applying specialized operators to relations.

2.	Relational Calculus
	Queries describe a desired set of tuples by specifying
	a predicate the tuples must satisfy.


Relational algebra is an abstract language, by which we mean that it is
not possible to execute queries formulated in relational algebra on an 
actual computer. We use relational algebra in order to express in the simplest
form, the set of operations that any relational database query 
language must perform. These basic operations ar every helpful in understanding 
SQL queries.
  • Basic Operations
    1. Union (R U S) Set of tuples that are in R or S or both. * R and S must have the same structure
    2. Difference (R - S) * Set of tuples in R but not in S.
    3. Intersection
    4. Cartesian Product (R * S)
    5. Project
    6. Select
    7. Join
    8. Division (Quotient)
    Example, A B C D E F ----------- ---------- a b c b g a d a f d a f c b d ---------- ----------- R S
  • Relational Algebra Vs. Relational Calculus
    1. Relational calculus represents an alternative to relational algebra.
    2. Both are equivalent to one another, i.e., for each expression of the relational algebra there is an equivalent in the calculus, likewise.
    3. The Calculus is closer to natural language, where the algebra is more like a programming language.
    4. The calculus simply states what the problem is, the algebra gives a procedure for solving that problem.
    5. Relational calculus-based languages are higher-level than the algebraic ones because the algebra specifies the order of operations while the calculus leaves it to a compiler to determine the most efficient order of evaluation.
  • Last update October 27, 1997.