The Relational Model

by K. Yue

1. Introduction

Example:

MariaDB [toyu]> select * from student;
+--------+-----------+---------+-------+-------+---------+---------+
| stuId  | lname     | fname   | major | minor | credits | advisor |
+--------+-----------+---------+-------+-------+---------+---------+
| 100000 | Tony      | Hawk    | CSCI  | CINF  |      40 |    1011 |
| 100001 | Mary      | Hawk    | CSCI  | CINF  |      35 |    1011 |
| 100002 | David     | Hawk    | CSCI  | ITEC  |      66 |    1011 |
| 100003 | Catherine | Lim     | ITEC  | CINF  |      20 |    1017 |
| 100004 | Larry     | Johnson | ITEC  | NULL  |      66 |    1017 |
| 100005 | Linda     | Johnson | CINF  | ENGL  |      13 |    1015 |
| 100006 | Lillian   | Johnson | CINF  | ITEC  |      18 |    1015 |
| 100007 | Ben       | Zico    | NULL  | NULL  |      16 |    1014 |
| 100008 | Bill      | Ching   | ARTS  | ENGL  |      90 |    1018 |
| 100009 | Linda     | King    | ARTS  | CSCI  |     125 |    1018 |
+--------+-----------+---------+-------+-------+---------+---------+
10 rows in set (0.00 sec)

Example:

+--------+-----------+---------+-------+-------+---------+---------+
| stuId  | lname     | fname   | major | minor | credits | advisor |
+--------+-----------+---------+-------+-------+---------+---------+
| 100000 | Tony      | Hawk    | CSCI  | CINF  |      40 |    1011 |
| 100001 | Mary      | Hawk    | CSCI  | CINF  |      35 |    1011 |
| 100002 | David     | Hawk    | CSCI  | ITEC  |      66 |    1011 |
| 100003 | Catherine | Lim     | ITEC  | CINF  |      20 |    1017 |
| 100004 | Larry     | Johnson | ITEC  | NULL  |      66 |    1017 |
| 100005 | Linda     | Johnson | CINF  | ENGL  |      13 |    1015 |
| 100006 | Lillian   | Johnson | CINF  | ITEC  |      18 |    1015 |
| 100007 | Ben       | Zico    | NULL  | NULL  |      16 |    1014 |
| 100008 | Bill      | Ching   | ARTS  | ENGL  |      90 |    1018 |
| 100009 | Linda     | King    | ARTS  | CSCI  |     125 |    1018 |
+--------+-----------+---------+-------+-------+---------+---------+

and

+--------+-----------+---------+---------+---------+-------+-------+
| stuId  | fname     | lname   | credits | advisor | major | minor |
+--------+-----------+---------+---------+---------+-------+-------+
| 100008 | Bill      | Ching   |      90 |    1018 | ARTS  | ENGL  |
| 100002 | David     | Hawk    |      66 |    1011 | CSCI  | ITEC  |
| 100001 | Mary      | Hawk    |      35 |    1011 | CSCI  | CINF  |
| 100000 | Tony      | Hawk    |      40 |    1011 | CSCI  | CINF  |
| 100004 | Larry     | Johnson |      66 |    1017 | ITEC  | NULL  |
| 100006 | Lillian   | Johnson |      18 |    1015 | CINF  | ITEC  |
| 100005 | Linda     | Johnson |      13 |    1015 | CINF  | ENGL  |
| 100009 | Linda     | King    |     125 |    1018 | ARTS  | CSCI  |
| 100003 | Catherine | Lim     |      20 |    1017 | ITEC  | CINF  |
| 100007 | Ben       | Zico    |      16 |    1014 | NULL  | NULL  |
+--------+-----------+---------+---------+---------+-------+-------+

stores the same information.
 

Null values:

Example:

Consider the attribute SpouseName. A Null value may mean:

  1. not applicable: the person is not married.
  2. missing information: the person is married but we do not have the name of the spouse.
  3. no information at all: we do not know whether the person is married or not.

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:

MariaDB [toyu]> select * from department;
+----------+------------------------------+------------+------------+
| deptCode | deptName                     | schoolCode | numFaculty |
+----------+------------------------------+------------+------------+
| ACCT     | Accounting                   | BUS        |         10 |
| ARTS     | Arts                         | HSH        |          5 |
| CINF     | Computer Information Systems | CSE        |          5 |
| CSCI     | Computer Science             | CSE        |         12 |
| ENGL     | English                      | HSH        |         12 |
| ITEC     | Information Technology       | CSE        |          4 |
+----------+------------------------------+------------+------------+
6 rows in set (0.00 sec)

MariaDB [toyu]> select * from faculty;
+-------+----------+----------+----------+---------------------+
| facId | lname    | fname    | deptCode | rank                |
+-------+----------+----------+----------+---------------------+
|  1011 | Paul     | Smith    | CSCI     | Professor           |
|  1012 | Mary     | Tran     | CSCI     | Associate Professor |
|  1013 | David    | Love     | CSCI     | Associate Professor |
|  1014 | Sharon   | Mannes   | CSCI     | Assistant Professor |
|  1015 | Daniel   | Kim      | CINF     | Professor           |
|  1016 | Andrew   | Byre     | CINF     | Associate Professor |
|  1017 | Deborah  | Gump     | ITEC     | Professor           |
|  1018 | Art      | Allister | ARTS     | Assistant Professor |
|  1019 | Benjamin | Yu       | ITEC     | Lecturer            |
|  1020 | Katrina  | Bajaj    | ENGL     | Lecturer            |
|  1021 | Jorginlo | Neymar   | ACCT     | Assistant Professor |
+-------+----------+----------+----------+---------------------+
11 rows in set (0.00 sec)

Exercise:

(1) Give a realistic example of a relation with two candidate keys. State the assumptions you have made.


More about keys:

Consider the example above. The attribute deptCode is a foreign key in the relation faculty, referencing department(deptCode)

Example:

MariaDB [toyu]> select * from faculty;
+-------+----------+----------+----------+---------------------+
| facId | fname    | lname    | deptCode | rank                |
+-------+----------+----------+----------+---------------------+
|  1011 | Paul     | Smith    | CSCI     | Professor           |
|  1012 | Mary     | Tran     | CSCI     | Associate Professor |
|  1013 | David    | Love     | CSCI     | Associate Professor |
|  1014 | Sharon   | Mannes   | CSCI     | Assistant Professor |
|  1015 | Daniel   | Kim      | CINF     | Professor           |
|  1016 | Andrew   | Byre     | CINF     | Associate Professor |
|  1017 | Deborah  | Gump     | ITEC     | Professor           |
|  1018 | Art      | Allister | ARTS     | Assistant Professor |
|  1019 | Benjamin | Yu       | ITEC     | Lecturer            |
|  1020 | Katrina  | Bajaj    | ENGL     | Lecturer            |
|  1021 | Jorginlo | Neymar   | ACCT     | Assistant Professor |
+-------+----------+----------+----------+---------------------+
11 rows in set (0.00 sec)

MariaDB [toyu]> select * from department;
+----------+------------------------------+------------+------------+
| deptCode | deptName                     | schoolCode | numFaculty |
+----------+------------------------------+------------+------------+
| ACCT     | Accounting                   | BUS        |         10 |
| ARTS     | Arts                         | HSH        |          5 |
| CINF     | Computer Information Systems | CSE        |          5 |
| CSCI     | Computer Science             | CSE        |         12 |
| ENGL     | English                      | HSH        |         12 |
| ITEC     | Information Technology       | CSE        |          4 |
+----------+------------------------------+------------+------------+
6 rows in set (0.00 sec)

MariaDB [toyu]> select f.fname, f.lname, f.deptCode, d.deptName
    -> from faculty f join department d on (f.deptCode = d.deptCode);
+----------+----------+----------+------------------------------+
| fname    | lname    | deptCode | deptName                     |
+----------+----------+----------+------------------------------+
| Paul     | Smith    | CSCI     | Computer Science             |
| Mary     | Tran     | CSCI     | Computer Science             |
| David    | Love     | CSCI     | Computer Science             |
| Sharon   | Mannes   | CSCI     | Computer Science             |
| Daniel   | Kim      | CINF     | Computer Information Systems |
| Andrew   | Byre     | CINF     | Computer Information Systems |
| Deborah  | Gump     | ITEC     | Information Technology       |
| Art      | Allister | ARTS     | Arts                         |
| Benjamin | Yu       | ITEC     | Information Technology       |
| Katrina  | Bajaj    | ENGL     | English                      |
| Jorginlo | Neymar   | ACCT     | Accounting                   |
+----------+----------+----------+------------------------------+
11 rows in set (0.00 sec)

MariaDB [toyu]> select * from student;
+--------+-----------+---------+-------+-------+---------+---------+
| stuId  | fname     | lname   | major | minor | credits | advisor |
+--------+-----------+---------+-------+-------+---------+---------+
| 100000 | Tony      | Hawk    | CSCI  | CINF  |      40 |    1011 |
| 100001 | Mary      | Hawk    | CSCI  | CINF  |      35 |    1011 |
| 100002 | David     | Hawk    | CSCI  | ITEC  |      66 |    1011 |
| 100003 | Catherine | Lim     | ITEC  | CINF  |      20 |    1017 |
| 100004 | Larry     | Johnson | ITEC  | NULL  |      66 |    1017 |
| 100005 | Linda     | Johnson | CINF  | ENGL  |      13 |    1015 |
| 100006 | Lillian   | Johnson | CINF  | ITEC  |      18 |    1015 |
| 100007 | Ben       | Zico    | NULL  | NULL  |      16 |    1014 |
| 100008 | Bill      | Ching   | ARTS  | ENGL  |      90 |    1018 |
| 100009 | Linda     | King    | ARTS  | CSCI  |     125 |    1018 |
+--------+-----------+---------+-------+-------+---------+---------+
10 rows in set (0.00 sec)

MariaDB [toyu]> select * from faculty;
+-------+----------+----------+----------+---------------------+
| facId | fname    | lname    | deptCode | rank                |
+-------+----------+----------+----------+---------------------+
|  1011 | Paul     | Smith    | CSCI     | Professor           |
|  1012 | Mary     | Tran     | CSCI     | Associate Professor |
|  1013 | David    | Love     | CSCI     | Associate Professor |
|  1014 | Sharon   | Mannes   | CSCI     | Assistant Professor |
|  1015 | Daniel   | Kim      | CINF     | Professor           |
|  1016 | Andrew   | Byre     | CINF     | Associate Professor |
|  1017 | Deborah  | Gump     | ITEC     | Professor           |
|  1018 | Art      | Allister | ARTS     | Assistant Professor |
|  1019 | Benjamin | Yu       | ITEC     | Lecturer            |
|  1020 | Katrina  | Bajaj    | ENGL     | Lecturer            |
|  1021 | Jorginlo | Neymar   | ACCT     | Assistant Professor |
+-------+----------+----------+----------+---------------------+
11 rows in set (0.00 sec)

MariaDB [toyu]> select s.fname, s.lname, s.advisor, f.rank
    -> from student s join faculty f on (s.advisor = f.facId);
+-----------+---------+---------+---------------------+
| fname     | lname   | advisor | rank                |
+-----------+---------+---------+---------------------+
| Tony      | Hawk    |    1011 | Professor           |
| Mary      | Hawk    |    1011 | Professor           |
| David     | Hawk    |    1011 | Professor           |
| Catherine | Lim     |    1017 | Professor           |
| Larry     | Johnson |    1017 | Professor           |
| Linda     | Johnson |    1015 | Professor           |
| Lillian   | Johnson |    1015 | Professor           |
| Ben       | Zico    |    1014 | Assistant Professor |
| Bill      | Ching   |    1018 | Assistant Professor |
| Linda     | King    |    1018 | Assistant Professor |
+-----------+---------+---------+---------------------+
10 rows in set (0.00 sec)