Introduction to the relational model

by K. Yue

1. Introduction

The relational model is based on the concept of a relation. key definitions:

Example:

A tuple:

{SID: 123456, SNAME: "Johnson, Gary", MAJOR: "CSCI", GPA: 3.71}

The same tuple:

{SNAME: "Johnson, Gary", MAJOR: "CSCI", SID: 123456, GPA: 3.71}

Other possible representations:

(SID: 123456, SNAME: "Johnson, Gary", MAJOR: "CSCI", GPA: 3.71)

If the order for presentation is understood:

(123456, "Johnson, Gary", "CSCI", 3.71)

Example:

Student: {SID, SNAME, MAJOR, GPA}

or

Student(SID, SNAME, MAJOR, GPA)

Example:

A relation schema:

Student(SID, SNAME, MAJOR, GPA)

An instance of the relation:

SID SNAME MAJOR GPA
12345 Johnson MATH 3.33
13526 Yue CSCI 2.11
20010 Smith CSCI 3.94
10110 Bajaj MATH 3.22
11111 Ganta CSCI 3.78

Another instance of the relation:

SID SNAME MAJOR GPA
12345 Johnson MATH 3.55
13526 Yue CSCI 2.41
10110 Bajaj MATH 3.22
11111 Ganta CSCI 3.98

Null values:

Example:

Consider the SpouseName. A Null value may mean:

How do we distinguish between the three meanings of the null value in this case?

By using an extra attribute, such as MaritalStatus.

2. Keys

Example:

Consider the following relation instance:

A B C
12345 101 A
13098 201 B

Can you identify a candidate key?

Consider another relation instance.

StudentID CourseID Grade
12345 101 A
13098 201 B

Can you identify a candidate key?

What about this?

StudentID CourseID Grade
12345 101 A
13098 201 B
13098 101 C-
12345 201 D

Example:

Consider Employee(EmployeeID, EmployeeName)

If we make these assumptions:

We can conclude:

Example:

Consider R(EmployeeID, DepartmentID)

If we make these assumptions:

We can conclude that EmployeeID is the only candidate key for R.

Under a different set of assumptions, we may have different candidate keys

Assumptions:

Then we have two candidate keys: EmplyeeID and DepartmentID. The relation R may be called DepartmentHead.

Exercise:

A relation R has an arity of 5. What is the possible minimum and maximum number of superkeys of R?

A relation R has an arity of 5. What is the possible minimum and maximum number of candidate keys of R?

What about the general case?

Example:

Prove that a relation always has a candidate key.

Proof:

Since a relation is a set of tuples, the relation schema is always unique. If we can find a proper subset of relation schema that is a candidate key, we have found a candidate key. If not, the relation schema is minimal and is thus a candidate key.

Example:

Consider R(A,B,C) with two candidate keys A and B and S(A, D, E, F) with a single candidate key AD. A is a foreign key in S and the base table of A is R.