3. Relational Databases

3.01 Introduction

A relational database implements the Relational Model. By model we mean by model is that it serves as an abstraction to the complex real-world. Usually we will abstract data.

A relation, as defined by E. F. Codd., is a set of tuples (d1; : : : ; dn) where each element dj is a member of Dj.

A relation is approximately a table – so a relational database uses tables to represent data.

Relational Databases are an implementation of Relational Algebra, a theory for modelling data and defining queries on such data.

The following summarises a set of rules for Relational Databases.

  1. Everything is a relation
    • All operations use the relational model
    • All data is represented and accessed as relations
    • Table and database structure is accessed and altered as relations
  2. The system is unaffected by its implementation
    • If the hardware changes
    • If the operating system changes
    • If the discs are replaced
    • If data is distributed

The Relational Model is not the same as the Entity Relationship Model. An ER Model helps us model concepts, usually as part of the design of a Relational Database. SQL is a​ standard that attempts to implement the Relational Model.

3.02 Drawing a database: Basic Entity-Relationship diagrams

Some terms we need to know.

  • An entity is the thing we want to model. It must be uniquely identifiable and it may have attributes.
  • Attributes are information that describe an aspect of an entity.
  • A relationship is a connection or dependency between two entities.

How do we draw an entity? An entity is basically a box, with a word in it. eg:

An attribute is similar but we use an ellipse instead.

So to show an entity with an attribute we simply show them both with a line between the two.

In a database design you would see a box with lots of ellipses coming off it, because an entity would have many different attributes.

To show a relationship we draw a diamond, like this:

As we mentioned above, a relationship is a connection or dependency between two entities. So we can draw lines connecting entities to the relationship, like this:

We use words like “has student” to describe the relationship. In a simple example like this we could use “teaches”, etc – whatever it is that describes the relationship. You can give it a name that’s useful to you.

Tuesday 26 October 2021, 15 views

Leave a Reply

Your email address will not be published. Required fields are marked *