You are on page 1of 23

Database I

Background

The Relational Data Model

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.)

Examples of Attribute Domains

8
Alternative Terminology

Formal Terms Alternative1 Alternative2


Relation Table File
Tuple Row Record
Attribute Column Field

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}

 Usually written as:


n
X Di
i=1

 Any set of n-tuples from this Cartesian product is a


relation on the n sets

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

 This explains why


table rows in
relational model
are called tuples
 Relational schema
 Set of relation schemas, each with a distinct name
15
Properties of Relation
 Relation name is distinct from all other relation
names in relational schema
 Each cell of relation contains exactly one single
value
 Each attribute has a distinct name
 Values of an attribute are all from the same domain
 Each tuple is distinct; there are no duplicate tuples
 Order of attributes has no significance
 Order of tuples has no significance, theoretically
16
Relational Keys
 Super Key
 An attribute or set of attributes that uniquely
identifies a tuple in the relation
 Candidate Key
 A super key (K) such that no proper subset is a
super key within the relation
 In each tuple of R, values of K uniquely identify
that tuple (uniqueness)
 No proper subset of K has the uniqueness
property (irreducibility)
17
Relational Keys (Cont.)
 Composite Key
 A key which consists of more than one attribute
 Primary Key
 Candidate key selected to identify tuples uniquely within
relation
 Alternate Keys
 Candidate keys that are not selected to be primary key
 Foreign Key
 An attribute, or set of attributes, within one relation that
matches candidate key of some (possibly same) relation

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

You might also like