Chapter Two – The Relational Model
Page 4 of 38
• Oracle Database Express Edition (XE) 11g Release 2:
• DBC–e08-ODB-Art-Course-Database-Create-Tables.sql
• DBC–e08-ODB-Art-Course-Database-Insert-Data.sql
• DBC–e08-ODB-Art-Course-Database-SQL-Queries-CH01.sql
• MySQL 5.7:
• DBC–e08-MySQL-Art-Course-Database-Create-Tables.sql
• DBC–e08-MySQL-Art-Course-Database-Insert-Data.sql
• The goal of this chapter is to present an overview of the major elements of the
relational model. This includes the definition of a relation, important terminology, the
use of surrogate keys, and basic design principles.
• Students often misconstrue the statement that only a single element is allowed in a
cell to mean that the cells must be fixed in length. One can have a variable length
memo in a cell but that is considered, semantically, to be one thing. By the way,
there are a number of reasons for this restriction. Perhaps the easiest to explain is
that SQL has no means for addressing sub-elements in a cell.
• When students execute SQL SELECTs, they may generate relations with duplicate
rows. Such results do not fit the definition of relations, but they are considered
relations nonetheless. This is a good example of “theory versus practice”.
• You may want to emphasize that foreign keys and the primary key that they
reference need not have the same name. They must, however, have the same
underlying set of values (domain). This means that the values not just look the
same; it means that the values mean the same thing. A foreign key of CatName and
a foreign key of ValentineNickName might look the same, but they do not mean the
same thing. Using ValentineNickName as a foreign key to Name in the relation CAT
would result in some weird results.
• Referential integrity constraints are important. You might ask the students to think of
an example when a foreign key does not have a referential integrity constraint
(answer: whenever a parent row is optional, say, STUDENTs need not have an
ADVISER).
• We favor the use of surrogate keys. Unless there is a natural, numeric ID (like
PartNumber), we almost always add a surrogate key to our database designs.
Sometimes a surrogate key will be added even if there is a natural, numeric ID for
consistency. Surrogate keys can cause problems (primarily patching up foreign
keys) if the database imports data from other databases that either do not employ a
surrogate key or use a different one. In some cases, institutions have developed
policies for ensuring that surrogate keys are unique globally. It’s probably best for
the students to get into the habit of using them and consider not using them as an
exception. Professional opinions vary on this, however.