Rel359 icon

Rel359


A Relational Database Tool for M359 Students

Using Rel359

Rel359 screenshot

The main window of Rel359 contains two main panes. Simply type M359 Language statements into the bottom pane, click the Run button (or press F5) and the results are shown in the upper pane.

One of the design goals of Rel359 was to support all M359 Language statements exactly as described in the course text. This was almost achieved and any differences are listed below. (See Limitations for more infomation about these differences.)

  • Rel359 does not support domains, it only supports simple types of CHAR, INTEGER & RATIONAL. If you have installed the Java SDK then you should be able create additional custom types but this has not been tested in Rel359 and is not documented on this site.
  • Rel359 does not support dates. Dates are treated as strings and therefore don't sort or compare properly unless entered using a format such at ISO 8601 (YYYY-MM-DD).
  • Rel359 does not support foreign keys.
  • Rel359 only supports a limited number of M359 style constraints. (Currently upto 1000 M359 style constraints are supported.)
  • Rel359 does not support comments when defining relations.
  • Rel359 requires imperative statements to be terminated with a semicolon.

M359 Language Examples

The following table lists examples of M359 Language statements and how they can be used in Rel359.

operator example comment
select select Enrolment where CourseCode = 'c4' as in the course text
project project Enrolment over StudentId, CourseCode as in the course text
join Enrolment join Student as in the course text
rename Student join (Region rename (Address as RegionAddress, EmailAddress as RegionEmailAddress)) as in the course text
alias ExamAndEnrolDetails alias (Enrolment join Examination); requires a semicolon at the end
divide divide SupplyParts by AllParts as in the course text 
intersection (project Student over Name, Address) intersection (project Staff over Name, Address) as in the course text
union BasicStudent union NewStudent as in the course text 
difference BasicStudent difference ExStudent as in the course text 
times project (select (Enrolment times ( Student rename (StudentId as StudentIdent))) where StudentId = StudentIdent) over StudentId, CourseCode, EnrolmentDate, Name, Address, EmailAddress, RegistrationDate, RegionNumber as in the course text 
constraint constraint (select (Enrolment join Student) where EnrolmentDate < RegistrationDate) is empty; requires a semicolon at the end
a maximum of 1000 constraints are supported 
relation relation OwnsHouse
    Address: CHAR
    Ref: CHAR
    WhenLastSold: INTEGER
    primary key (Address, Ref);
requires a semicolon at the end
composite keys are supported
primary key

alternate key
relation OwnsHouse
    Address: CHAR
    Ref: CHAR
    primary key Address
    alternate key Ref;
requires a semicolon at the end
multiple alternate keys are supported
comments are not supported
foreign keys are not supported

Notes

Case sensitivity - Rel359 requires 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.

Rel359 System Relations

In addition to any relations created by the user, Rel359 contains a number of system relations which contain information about Rel359 and metadata about all the other relations. These relations should support all the relational operators mentioned above but you should not attempt to modify these relations directly. However several of these relations contain information that is useful to the user.

  • sys.Catalog - contains details of all other relations, both system and user. Select from this relation to find all the relations that you have defined.
  • sys.Constraints - contains details of all the constraints defined in the database. If you wish to delete a constraint, you will need to select from this to find its name.
  • sys.Version - contains version, license and copyright information about Rel359.

Non M359 Language Operators

The M359 Language is incomplete in that it does not contain any operators for inserting, updating or deleting data in relvars. It also contains no operators for deleting relations, constraints, etc.

Since Rel359 is based on Rel it inherits Tutorial D style operators for features that are not in the M359 Language.

Populating Relations

Relations can be populated with single tuples....
    Ward := RELATION { TUPLE {WardNo "w10" , WardName "Arden" , NumberOfBeds 12 }};
....or by multiples
    Ward := RELATION {
        TUPLE {WardNo "w11" , WardName "Feldon" , NumberOfBeds 12 },
        TUPLE {WardNo "w12" , WardName "Avon" , NumberOfBeds 8 },
        TUPLE {WardNo "w13" , WardName "Mendip" , NumberOfBeds 10 }};

This syntax overwrites any existing tuples in the relation.

Insert

Tuples can be inserted singly....
    INSERT Ward RELATION { TUPLE {WardNo "w10" , WardName "Arden" , NumberOfBeds 12 }};
....or in multiples
    INSERT Ward RELATION {
        TUPLE {WardNo "w11" , WardName "Feldon" , NumberOfBeds 12 },
        TUPLE {WardNo "w12" , WardName "Avon" , NumberOfBeds 8 },
        TUPLE {WardNo "w13" , WardName "Mendip" , NumberOfBeds 10 }};

Delete

Tuples can be deleted selectively....
    DELETE Ward WHERE WardNo = "w11";
....or all the tuples in a relation
    DELETE Ward;

Note that after running the last line of code above, the Ward relation will be empty but it will still exist. To delete the entire relation use
    DROP Ward;

When specifing data in relations or comparisions CHAR types must be enclosed in 'single quotes' or "double quotes"; INTEGER and RATIONAL types must not have quotes and RATIONAL types must contain a decimal point.

When adding, deleting or modifying any data, constraints must be respected otherwise an error will be thrown. When attempting to delete relations, the delete will fail if anything depends on the relation. In particular constraints and aliases depend on other relation and these constraints or aliases must be deleted first.

Constraints

In the M359 Language constraints are defined in the context of a relation and are not named. However constraints need to be named so that they can be identified if you want to delete them later. Rel359 therefore automatically selects a name when you create a constraint using the M359 Language syntax.

For example if you create a constraint such as
    constraint (select (Enrolment join Student) where EnrolmentDate < RegistrationDate) is empty;

Rel359 constraint result You can find its name by running select sys.Constriants and in this case you can see the constraint is named c5.

Having found the name, you can delete the constraint as follows:
    DROP constraint c5;

If you want to control the name of a constraint yourself, Rel359 also supports naming of contraints when you create them. This is acheived by including the name after the constraint keyword. For example:
    constraint MyConstraint (select (Enrolment join Student) where EnrolmentDate < RegistrationDate) is empty;

Note that using named constraints such as this is outside the M359 Langauge and should not be used in any assignments.

Foreign keys

Rel359 does not support M359 Language style foreign keys, but you can use contraints to do the same job. For example the foreign key in the realtion definition for Student:
    foreign key RegionNumber references Region

can be implemented using
    constraint ((project Student over RegionNumber) difference (project Region over RegionNumber)) is empty;

Note that this syntax includes the attribute being referred to which is missing in the definition of the M359 Language.

page last updated: Thursday, December 31, 2015