You are on page 1of 5

University of Kirkuk

College of Computer Science & Information Technology


Computer Science Department
2nd Year.
Database Analysis and Design Part I
Dr. Baban A. Mahmood & M.Sc. Banaz A. Qader

Lecture 5

Relational Model [1] Chapter 3


Relational Model.
The relational model uses a collection of tables to represent both data and the
relationships among those data. Each table has multiple columns, and each column
has a unique name.

Figure 5.1: Instances of Branch and Staff Relations.

The Branch table of Figure 5.1 stores information about branches, consisting of
brachNO, street, city, and pstcode, for each branch. Note that each branch is
identified by the value of the column branchNo.

In general, a row in a table represents a relationship among a set of values.


1
University of Kirkuk
College of Computer Science & Information Technology
Computer Science Department
2nd Year.
Database Analysis and Design Part I
Dr. Baban A. Mahmood & M.Sc. Banaz A. Qader

In mathematical terminology, a tuple is simply a sequence (or list) of values. A


relationship between n values is represented mathematically by an n-tuple of
values.
Table 5.1: Alternative terminology for relational model terms.

Definitions:
Relation: A relation is a table with columns and rows.
Attribute: An attribute is a named column of a relation.
Tuple: A tuple is a row of a relation.
Degree: The degree of a relation is the number of attributes it contains. The
degree of a relation is a property of the intension of the relation.
Relation instance: It refers to a specific instance of a relation, i.e., containing a
specific set of rows.
Cardinality: The cardinality of a relation is the number of tuples it contains. The
cardinality is a property of the extension of the relation and is determined from the
particular instance of the relation at any given moment
Relational database: a collection of normalized relations with distinct relation
names.
Domain of Attributes: It is the set of permitted values for each attribute of a
relation.
The null value: It is a special value that signifies that the value is unknown or
does not exist.

2
University of Kirkuk
College of Computer Science & Information Technology
Computer Science Department
2nd Year.
Database Analysis and Design Part I
Dr. Baban A. Mahmood & M.Sc. Banaz A. Qader

Figure 5.2: Domains for some attributes of the Branch and Staff relations.

Properties of Relations
A relation has the following properties:
 the relation has a name that is distinct from all other relation names in the
relational schema;
 each cell of the relation contains exactly one atomic (single) value;
 each attribute has a distinct name;
 the values of an attribute are all from the same domain;
 each tuple is distinct; there are no duplicate tuples;
 the order of attributes has no significance;
 the order of tuples has no significance, theoretically. (However, in practice, the
order may affect the efficiency of accessing tuples).

Relational Keys:
Relational keys are one or more attributes that uniquely identifies each tuple in a
relation.

1. Superkey
An attribute, or set of attributes, that uniquely identifies a tuple within a relation.
A superkey may contain extraneous attributes. For example, the combination of
branchNO and street is a superkey for the relation branch. If K is a superkey, then
so is any superset of K.
3
University of Kirkuk
College of Computer Science & Information Technology
Computer Science Department
2nd Year.
Database Analysis and Design Part I
Dr. Baban A. Mahmood & M.Sc. Banaz A. Qader

Formally, let R denote the set of attributes in the schema of relation r. If we


say that a subset K of R is a superkey for r , we are restricting consideration
to instances of relations r in which no two distinct tuples have the same values
on all attributes in K. That is, if t1 and t2 are in r and t1 ≠ t2, then t1.K ≠ t2.K.

2. Candidate key
A superkey such that no proper subset is a superkey within the key relation.
A candidate key, K, for a relation R has two properties:
 uniqueness – in each tuple of R, the values of K uniquely identify that tuple;
 irreducibility – no proper subset of K has the uniqueness property.

There may be several candidate keys for a relation. Consider the Branch
relation shown in Figure 5.1. Given a value of city, we can determine several
branch offices (for example, London has two branch offices). This attribute cannot
be a candidate key. On the other hand, by branchNo, we can determine at most
one tuple, so that branchNo is a candidate key. Similarly, postcode is also a
candidate key for this relation.

Note that an instance of a relation cannot be used to prove that an attribute or


combination of attributes is a candidate key.

The fact that there are no duplicates for the values that appear at a particular
moment in time does not guarantee that duplicates are not possible. However, the
presence of duplicates in an instance can be used to show that some attribute
combination is not a candidate key.

Identifying a candidate key requires that we know the ‘real world’ meaning of
the attribute(s) involved so that we can decide whether duplicates are possible.

3. Composite key
A key that consists of more than one attribute. The two attributes (clientNO,
propertyNo) constitute a candidate key (composite) for the viewing relation shown
in Figure 5.3.

4
University of Kirkuk
College of Computer Science & Information Technology
Computer Science Department
2nd Year.
Database Analysis and Design Part I
Dr. Baban A. Mahmood & M.Sc. Banaz A. Qader

Given a client number, clientNo, there may be several corresponding viewings for
different properties. Similarly, given a property number, propertyNo, there may be
several clients who viewed this property. Therefore, clientNo by itself or
propertyNo by itself cannot be selected as a candidate key. However, the
combination of clientNo and propertyNo identifies at most one tuple, so, for the
Viewing relation, clientNo and propertyNo together form the (composite)
candidate key.
If we need to consider the possibility that a client may view a property more than
once, then we could add viewDate to the composite key. However, we assume that
this is not necessary.

Figure 5.3: the Viewing Relation

4. Primary key
The candidate key that is selected to identify tuples uniquely within the key
relation.
The primary key should be chosen such that its attribute values are never, or very
rarely, changed.

5. Foreign key
An attribute, or set of attributes, within one relation r1 that matches the candidate
key (or primary key) of another relation r2.

The relation r1 is also called the referencing relation of the foreign key
dependency, and r2 is called the referenced relation of the foreign key.

For example, in Figure 5.1, in the Branch relation, branchNo is the primary key.
However, in the Staff relation, the branchNo is a foreign key.
5

You might also like