Week03 - The Relational Data Model
Week03 - The Relational Data Model
Background
1
History of Relational Data
Model
Proposed by E.F. Codd, in his research paper “A
relational model of data for large shared data banks”
in 1970
Objectives of RDM:
High degree of data independence
Application program must not be affected by modifications
to the internal data representation
Provide environment for dealing with data consistency and
redundancy problems
The first prototype of Relational Database
Management System (RDBMS) “System R” was
developed by IBM’s San Joes Research Laboratory
in late 1970s 2
History of Relational Data
Model (Cont.)
SystemR project led to two major
developments:
The development of SQL (pronounced as “See-
Quel”)
Production of various commercial RDBMS
products during 1980, i.e. DB2 and SQL/DS from
IBM and ORACLE from ORACLE Corporation
3
Basic Terminology
Relation
A relation is a table with columns and rows
In relational model a database is perceived by the user as
tables
However this perception applies only to the logical
structure i.e. external and conceptual levels
Attribute
A named column of a relation
Attributes can appear in any order and the relation will still
be the same relation
Tuple
Tuple is a row of a relation
It is also called the extension or state of a relations which
changes over the time
4
Tuples are also called records
Basic Terminology (Cont.)
Domain
A set of allowable values for one or more attributes
Structure of relation, together with the specification
of the domains is called intension of a relation
Degree
The number of attributes a relation contains
A relation with only one attribute would have degree
one can be called a unary relation
5
Basic Terminology (Cont.)
A relation with two attribute is called binary and
one with three attributes are called ternary, and
after that the term n-ary is used
Cardinality
The number of tuples a relation contains
The cardinality is the property of extension of the
relation
6
Basic Terminology (Cont.)
7
Basic Terminology (Cont.)
8
Alternative Terminology
9
Mathematical Definition of
Relation
To understand the meaning of the term relation,
let us review some concepts from mathematics
Consider two sets, D1 & D2, where
D1 = {2, 4}
D2 = {1, 3, 5}
Cartesian product, D1 x D2, is set of all ordered
pairs, where first element is member of D1 and
second element is member of D2
D1 x D2 = {(2, 1), (2, 3), (2, 5), (4, 1), (4, 3), (4, 5)} 10
Mathematical Definition of
Relation (Cont.)
Any subset of Cartesian product is a relation; e.g.
R = {(2, 1), (4, 1)}
We can specify which pairs are in relation using
some condition for selection; e.g.
Second element is 1:
R = {(x, y) | x∈D1, y∈D2, and y = 1}
First element is always twice the second:
S = {(x, y) | x∈ D1, y∈D2, and x = 2y}
11
Mathematical Definition of
Relation (Cont.)
Considerthree sets D1, D2, D3 with Cartesian
Product D1 x D2 x D3; e.g.
D1 = {1, 3} D2 = {2, 4} D3 = {5, 6}
D1 x D2 x D3 = {(1,2,5), (1,2,6), (1,4,5),
(1,4,6), (3,2,5), (3,2,6), (3,4,5), (3,4,6)}
Again any subset of these ordered triples is a
relation
12
Mathematical Definition of
Relation (Cont.)
So Cartesian product of n sets (D1, D2, . . ., Dn) is:
D1 x D2 x . . . x Dn = {(d1, d2, . . . , dn) | d1∈ D1, d2∈ D2, . . . , dn∈ Dn}
13
Database Relations
Now applying the previous concepts to
database, we have:
Relation Schema:
Relation is defined by a set of attribute and
domain name pairs
In our example, the branch relation on next slide
has four attributes with corresponding domains
(tuples)
So the branch relation can be represented as:
14
Database Relations (Cont.)
{(BNo:B005, Street:22 Deer Rd, City:London,
Postcode:SW1 4EH)}
Attribute Domain
18
Relational Integrity
Relational Integrity or Integrity Constraints are
set of rules, which insure that the data is
accurate
Null represents value for an attribute that is
currently unknown or not applicable for tuple
Null is not the same as zero or spaces, which
are values
Domain Constraints
Restriction on the set of values allowed for the
attribute of relation
19
Relational Integrity (Cont.)
Entity Integrity
Applies to the primary keys of base relations
Base relation is corresponding to an entity in the
conceptual schema, whose tuples are stored
physically in database
According to entity integrity in a base relation, no
attribute of a primary key can be null
Referential Integrity
The foreign key value must match a candidate key
value of some tuple in its home relation or foreign key
value must be null
20
Relational Integrity (Cont.)
Enterprise Constraints
Rules specified by the users or DBAs of a
database
21
Views
A view is a Virtual Relation or in other words
a relation that does not exist
So the external level of the three level
architecture can consists of both the base
relations and views
Contents of a view are defined as a query on
one or more base relations
Views are dynamic, meaning that changes
made to base relations that affect view
attributes are immediately reflected in the
view 22
Purpose of View
Provides powerful and flexible security
mechanism by hiding parts of database from
certain users
Permits users to access data in a customized
way, so that same data can be seen by
different users in different ways, at same time
Can simplify complex operations on base
relations
All updates to a base relation should be
immediately reflected in all views that
reference that base relation and vice versa 23