MORE ON RELATIONAL ALGEBRA VS. CALCULUS
with Hugh Darwen

 

 

 

From: BW

To: Editor

Date: 18 Feb 2005

 

Further to EM's question on your site today about the differences between relational algebra and relational calculus, Suzanne W.Dietrich in her book "Understanding Relational Database Query Languages" says this at the beginning of chapter 2: "Relational algebra is a procedural query language that applies specific operators to a relation [...]". At the beginning of chapter 3 she writes: "Relational calculus is a declarative query language and indicates the properties of the data [...] instead of the procedural paradigm of relational algebra [...]".

 

I found this to be a simple way of thinking about the difference - perhaps it will help some of your other readers.

 

She goes on to describe the tuple relational calculus (TRC) - where variables range over the tuples of a relation - and the domain relational calculus (DRC), where the variables range over the domain of an attribute. She also describes a by-position syntax, and a by-name syntax for the DRC.

 

Her answer to Chris Date's exercise for the reader is that SQL is based on the tuple relational calculus.

 

It's quite a good book that some of your readers might find interesting. It uses a set of worked examples in relational algebra, DRC, TRC and SQL to show many of the pros and cons of each notation in an accessible way, and to provide an effective comparison.

 

Disclaimer: I have no connection with Dr. Dietrich or her publishers.

 

 

Hugh Darwen Responds: I have never quite understood why a language closely based on the algebra should be called "procedural" (as opposed to "declarative"). Nobody ever described Fortran's numerical expressions that use +, -, * and / (among others) as procedural, did they?

 

For that matter, I'm not too happy with the term "declarative" either, of expressions that denote values.  For me, a typical computer language in the imperative style consists of statements (strictly, statement types), a.k.a. commands or imperatives.  And statements sometimes include expressions that denote values.  Some statements are procedural, others declarative. The declarative ones are mainly variable declarations, though in SQL some of these show up as procedural statements, such as CREATE TABLE.

 

As for "applies specific operators to a relation", I cannot imagine why anybody should find that helpful, even if we forgive the sloppiness. If they do find it helpful, I dread to think what misapprehensions they might be suffering from.  Which relation in particular?  What's the significance of "specific"?

 

As for "relational calculus ... indicates the properties of the data", I cannot imagine why anybody should find that helpful either.  Again, I dread to think what misapprehensions they might be suffering from.  I wonder which particular properties the writer was thinking of.

 

I'm not sure it's appropriate to refer to relational algebra and relational calculus as languages.  In the context in which these terms usually appear, the reader would surely expect that to mean, specifically, computer language.  In any case, an algebra is surely a concept, not a notation.  (I don't know what a calculus is, precisely, because no mathematician has ever been able to explain this term for me!)

 

SQL's <query expression>s have elements apparently inspired by Codd's calculus-style notation, but they additionally have UNION, JOIN and GROUP BY (for example).  I prefer to characterise SQL as just idiosyncratic, but then I would, wouldn't I?  (I'm also happy to omit the "syncra" bit from that adjective, as you know!)

 

 

Posted 4/15/05