Re: Expressing SQL in relational algebra

From: Bob Badour <bbadour_at_golden.net>
Date: 1 Apr 2003 23:24:04 -0800
Message-ID: <cd3b3cf.0304012324.7a12a665_at_posting.google.com>


pbrazier_at_cosmos-uk.co.uk (Paul) wrote in message news:<51d64140.0304010607.bce82c2_at_posting.google.com>...
> neo55592_at_hotmail.com (Neo) wrote in message news:<4b45d3ad.0303280739.6213c846@posting.google.com>...
> > How can I express "John likes Mary" using relational algebra using
> > only "John", "likes", "Mary", intersection operator(^) and grouping
> > operators ("()")? The expression should not find "Mary likes John",
> > "like John Mary", etc. Would the following expression be correct:
> > (((John ^ John) ^ likes) ^ Mary)
>
> I think you might be going to a lower level here to something that is
> outside the scope of relational algebra.

Neo is just confused. He doesn't know what he is talking about, and he has no interest in (or perhaps no ability for) learning.

> Say you have an employee relation with columns for the employee id,
> name, dept and salary. Then you can think of this as a logical
> predicate or a "template" sentence that can either be true or false.
> i.e.
>
> "employee E is called N, works for dept D and is on salary S"
>
> any row in the corresponding relation will be a true sentence
> (proposition) like:
>
> "employee 001 is called "John Smith", works for dept 10 and is on
> salary 20,000"
>
> so then if we use relational algebra to project this relation onto D
> say, we get
> the predicate:
>
> "there is an employee in dept D"
>
> the actual meaning (semantics) behind the sentences aren't known to
> the DBMS, it just does the algebra mechanically.

This is not entirely true. The conceptual model has a full predicate and the logical model has as much of the full predicate as feasible. The dbms does not know the external predicate, but it fully knows and understands the internal predicate.

> So in your example
> you'd have a relation L which corresponds to the sentence "A likes B",
> where A stands for the person doing the liking and B stands for the
> person being liked. So in relational algebra "John likes Mary" would
> just be L restricted to A=John and B=Mary.

If you read the Loves/Hates example I suggested to Neo earlier and took the time to read up on _The Principle of Orthogonal Design_, you would see that Date and McGoveran discourage the use of the relation name (in this case L) to encode information. Instead of a binary relation with A and B, a better design would use a trinary relation along the lines of (Subject, Verb, Object).

The postulate "John likes Mary" is simply the tuple: (Subject=John, Verb=likes, Object=Mary).

One might partially or fully instantiate the predicate of a relation L using some or all of the above.

<irrelevant treatise on NULL snipped> Received on Wed Apr 02 2003 - 09:24:04 CEST

Original text of this message