Rel and Rel359

Date last modified: 07 February, 2012

Back to home page

Rel is a prototype implementation of Tutorial D, a relational database language designed by Hugh Darwen and Chris Date specifically for teaching purposes.  Rel's author is Dave Voorhis of Derby University.

Rel359 is an adaptation of Rel by former M359 student John Waller.  Rel359 differs from Rel in that it uses the notation taught in M359 Block 2, where relevant, in place of Tutorial D notation (though in fact the two notations are very similar).

M359 students are not expected to have access to an implementation of the Block 2 notation, so you install and use Rel359 at your own risk.  I have tested it quite thoroughly and I use it for checking your TMA solutions.

Information about Rel359, including instructions for downloading it, can be found at http://www.jwaller.co.uk/rel359.  Note that you might need to install Java, for which instructions are also provided.  You should also download the scripts provided for creating and loading the University and Hospital databases used in M359.

I give a brief demo of Rel359 at my first tutorial.

Here are a few small points that you might need to take note of when you first start using Rel359.

You will be using the client program DBrowser, which is similar in concept to the ISQL program that you use for SQL exercises with the DBMS SQL Anywhere in Block 3.

Telling DBrowser Which Database to Use

It's a good idea to keep the University and Hospital databases separate (in different directories).  I did this by making empty directories named University and Hospital and switching to the appropriate one before loading the corresponding script file for creating that database.  Here's how to do that.

In the DBrowser window, just below the main menu is a line labelled "Location".  Immediately following the label is a box in which the directory containing the database is specified.  You can overtype this if you want to use a different database.  To the right of the box there is a small button labelled with just three dots (...).  Clicking on that lets you browse in the usual way to select the required directory.

If you invoke DBrowser from a command line, you can specify the required database by giving "-f" followed by its full path.  For example:  DBrowser.jar -f"d:\Rel359 Databases\University".  Note the enclosing double quotes, needed here only when the path includes blanks, as in this case.

DBrowser's "Backup" button

In the DBrowser window, lower pane, top right corner, there is a button labelled "Backup".  This is inherited from Rel's DBrowser but does not currently work.  In Rel it is used for backing up the entire database in the form of a Tutorial D script that can be run to recreate it.  That would be of no use to Rel359 users anyway, as they would need a Rel359 script.  In any case, scripts for (re)creating the M359 University and Hospital databases are provided at the Rel359 web site. 

DBrowser's display of results of relational expressions

DBrowser does not give a tabular display unless the Enhanced option is ticked.  When Enhanced is not ticked it uses Tutorial D notation for "spelling out" the contents of a relation.  (Rel359 uses the original Tutorial D notation here simply because M359 does not include any notation for this purpose.) 

Here is an example, starting with the query (in bold):

project Region over RegionNumber, EmailAddress
RELATION {RegionNumber INTEGER, EmailAddress CHAR} {
TUPLE {RegionNumber 1, EmailAddress "region1@open.fake.address"},
TUPLE {RegionNumber 2, EmailAddress "region2@open.fake.address"},
TUPLE {RegionNumber 3, EmailAddress "region3@open.fake.address"},
TUPLE {RegionNumber 4, EmailAddress "region4@open.fake.address"},
TUPLE {RegionNumber 5, EmailAddress "region5@open.fake.address"}}

Following the key word RELATION is a list of attribute definitions in braces and following that is a list of the tuples of the result, also in braces.  Each tuple is denoted by the key word TUPLE followed by a list of values for each attribute, also in braces.

Rel and Tutorial D

Here are some notes on Rel and Tutorial D for those who might be interested.

In case you would like to play with Rel itself, information and instructions for downloading it can be found at http://dbappbuilder.sourceforge.net/Rel.html.  Again, you might need to install Java, and again, instructions are also provided.

My book, "An Introduction to Relational Database Theory" (a free download) closely follows my Warwick University course and teaches Tutorial D.

Tutorial D includes a notation that is very similar to M359's for invoking operators of the relational algebra.  The differences are shown below.  Note that neither Tutorial D nor Rel359 have any counterpart of M359's foreign key syntax, for certain constraints that can equally well be expressed using the (project ... over ...) difference (project ... over ...) is empty formulation.

M359 Tutorial D
r1 join r2 same syntax in Tutorial D
r1 rename ( ... ) same syntax in Tutorial D
project r over a1, a2, ... r { a1, a2, ...}
select r where condition r where condition
r1 difference r2 r1 minus r2
r1 intersection r2 r1 intersect r2
r1 divide r2 not defined in Tutorial D
r1 times r2 not defined in Tutorial D but r1 join r2 is equivalent
relation-name alias ( relation-expression ) var relation-name virtual ( relation-expression ) ;
The defined name remains in existence until it is explicitly dropped by drop var relation-name;
relation relation-name
   attribute-name1  domain-name1
   atribute-name2   domain-name2

   .
   .
   .
var relation-name base relation
{ attribute-name1  domain-name1
   atribute-name2   domain-name2
  
.
   .
   . }

domain names (actually called type names) are restricted to CHAR, INTEGER, RATIONAL and user-defined types (beyond the scope of M359)

primary key ( ... ) key { ... }
alternate key ( ... ) key { ... }
foreign key ( ... ) not defined in Tutorial D (use constraint instead, as explained below)
constraint (relation-expression ) is empty constraint constraint-name is_empty ( relation-expression )

Notes

Braces { }

Note Tutorial D's habit of using braces { } to enclose lists where the order of the elements is of no significance, as is so often the case with relational constructs.

Semicolons

Tutorial D requires a semicolon at the end of an imperative (such as a var or constraint declaration).  Rel and Rel359 allow you to type in an expression to be evaluated (e.g., 2 + 2, or r1 join r2) in which case you must not put a semicolon at the end.

Case sensitivity

Rel and Rel359 require all names (of relations, attributes, etc.) to be spelled exactly as defined.  However, it is case-insensitive with respect to key words like join and where.

Foreign keys

Tutorial D does not support the foreign key shorthand for the very special kind of constraint that goes by that name in M359 and SQL.  However, the Tutorial D relational algebra has some useful additional operators that make the foreign key shorthand not worth having.

Consider foreign key RegionNumber references Region, specified in the relation definition for Student.  You can express this in Tutorial D like this (note the semicolon):

constraint StudentFKRegion is_empty ( Student not matching Region ) ;

r1 not matching r2 is equivalent to M359's r1 join ( ( project r1 over common-attrs ) difference ( project r2 over common-attrs ) ), where common-attrs is a list giving the names of the common attributes of r1 and r2.  Intuitively, it returns a relation consisting over those tuples of r1 that have no matching tuples in r2.  (There is also r1 matching r2, which gives those tuples of r1 that do have matching tuples in r2.)

Note that the not matching syntax to be used in place of foreign key syntax is much more general in its possible applications.  For example, it does not require the referenced relation to be a simple relation name and it does not require the referenced attributes to constitute a key of the referenced relation.

Tutorial D, like SQL, requires a constraint name to be given so that the constraint can be dropped if it is no longer required: drop constraint constraint-name ; (don't forget the semicolon).

Additional information

Rel is used extensively in one of the courses, CS252, on which I teach at Warwick University.  Materials for that course can be found at my web site at that university. These materials include things called worksheets, which  require the use of Rel.  They also include the official definition of Tutorial D, but in a form which might be hard reading for many M359 students.

The official definition of Tutorial D is taken from Databases, Types, and The Relational Model: The Third Manifesto by C.J. Date and Hugh Darwen, a book which I would recommend only to really keen students who might enjoy an in-depth exploration of relational theory, way beyond the requirements of M359!

A book that I do recommend for M359 students is Database in Depth, by C.J. Date, published by O'Reilly, ISBN 0-596-10012-4.  This book uses Tutorial D, as does Date's much bigger textbook Introduction to Database Systems (8th edition, Addison-Wesley, 2004)

Back to home page