5 Relational Model
5 Relational Model
Paolo Giorgini
Department of Information and
Communication Technology
University of Trento - Italy
http://www.dit.unitn.it/~pgiorgio
P. Giorgini 2
An Example
Juve Lazio 3 1
Lazio Milan 2 0
Juve Roma 1 2
Roma Milan 0 1
P. Giorgini 3
Attributes
We would like to have a non-positional structure for
relations. To do so, we associate a unique name
(attribute) with each domain of a relation which
describes the role of the domain.
In the tabular representation, attributes are used as
column headings
P. Giorgini 6
Examples
Relations on a single attribute are admissible:
Workers RegNum
6554
8765
P. Giorgini 7
Nested structures
P. Giorgini 8
Representation of
Nested Structures
Details Number Quantity Description Cost
1357 3 Covers 3.00
1357 2 Hors d'oeuvre 5.00
1357 3 First course 9.00
1357 2 Steak 12.00
2334 2 Covers 2.00
Receipts 2334 2 Hors d'oeuvre 2.50
2334 2 First course 6.00
Number Date Total
2334 2 Bream 15.00
1357 5/5/92 29.00
2334 2 Coffee 2.00
2334 4/7/92 27.50
3007 2 Covers 3.00
3007 4/8/92 29.50
3007 2 Hors d'oeuvre 6.00
3007 3 First course 8.00
3007 1 Bream 7.50
3007 1 Salad 3.00
3007 2 Coffee 2.00
P. Giorgini 9
Questions
P. Giorgini 10
More Detailed Representation
P. Giorgini 11
Incomplete Information
The relational model imposes a rigid structure on data:
information is represented by means of tuples;
P. Giorgini 12
Incomplete information:
Motivation
City GovtAddress
Roma Via IV novembre
Florence ?
Tivoli ??
Prato ???
P. Giorgini 13
Incomplete information:
Solutions
We should not use domain values (0, 99, empty string,
etc.) to represent lack of information:
Using unused values may lead to ambiguity and
confusion.
Unused values could become meaningful.
Within application programs, we should be able to
distinguish between actual values and placeholders.
For example, in order to calculate the average age of
a set of people, use 50 as default value for
unknown ages!
P. Giorgini 14
Incomplete Information
in the Relational Model
A simple but effective technique is adopted by the
Relational Model: use null values.
A null value isa special value (i.e., not a value of the
domain) which denotes the absence of a domain
value.
We could (and often should) put restrictions on the
presence of null values in tuples (more on this later.)
P. Giorgini 15
Types of Null Values
At least three different types are useful:
unknown value -- there is a domain value, but it is
not known (Florence);
non-existent value: the attribute is not applicable for
the tuple (Tivoli);
no-information value: we dont know whether a
value exists or not (Prato); this is the disjunction
(logical or) of the other two.
DBMSs do not distinguish between these types: they
implicitly adopt the no-information value.
P. Giorgini 16
A Meaningless Database
P. Giorgini 17
Integrity Constraints
An integrity constraint is a property that must be
satisfied by all meaningful database instances
A constraint can be seen as a predicate; a database is
legal if it satisfies all integrity constraints.
Types of constraints
Intra-relational constraints, with domain constraints
and tuple constraints as special cases;
Inter-relational constraints
P. Giorgini 18
Rationale for Integrity Constraints
Useful for describing the application in greater
detail.
Contribute to data quality
An element in the design process;
Used by the system in choosing a strategy for
query processing
P. Giorgini 19
Tuple and Domain Constraints
P. Giorgini 20
Unique Identification
for Tuples and Keys
P. Giorgini 22
Beware!
RegNum Surname FirstName BirthDate DegreeProg
296328 Smith John 29/04/59 Computing
587614 Smith Lucy 01/05/61 Engineering
934856 Black Lucy 01/05/61 Fine Art
965536 Black Lucy 05/03/58 Engineering
P. Giorgini 26
Referential Constraints (Foreign Keys)
P. Giorgini 27
Example of Referential Constraints
Offences Code Date Officer Dept Registartion
143256 25/10/1992 567 75 5694 FR
987554 26/10/1992 456 75 5694 FR
987557 26/10/1992 456 75 6544 XY
630876 15/10/1992 456 47 6544 XY
539856 12/10/1992 567 47 6544 XY
P. Giorgini 29
Violation of Referential Constraints
Offences Code Date Officer Dept Registartion
987554 26/10/1992 456 75 5694 FR
630876 15/10/1992 456 47 6544 XY
P. Giorgini 30
Referential Constraints:
Comments
Referential constraints play an essential role
in making the relational model value-based.
It is possible to have features that support the
management of referential constraints
(actions activated by violations)
Care is needed in case of constraints that
involve two or more attributes
P. Giorgini 31
Complications with Constraints
Accidents Code Dept1 Registration1 Dept2 Registration2
6207 75 6544 XY 93 9775 GF
6974 93 5694 FR 93 9775 GF
P. Giorgini 33