2 Rel Model
2 Rel Model
DATA MODEL
CHAPTER 3 (6/E)
CHAPTER 5 (5/E)
1
LECTURE OUTLINE
Relational Model Concepts
Relational Database Schemas
Update Operations
Brief History of Database Applications (from Section 1.7)
2
RELATIONAL MODEL CONCEPTS
Represent data as a collection of relations
Table of values
• Each row (tuple)
• Represents a record of related data values
• Facts that typically correspond to a real-world entity or relationship
• Each column (attribute)
• Holds a corresponding value for each row
• Slot for a specific interpretation for a row
3
RELATIONAL MODEL (CONT’D.)
4
DOMAINS
Domain D
• Set of atomic values
• {0,1,2,…}
• {Jo Smith, Dana Jones, Ashley Wong, Y. K. Lee,…}
Atomic
• Each value indivisible
Domain specified by Data type rather than by enumeration
• Integer, String, Date, Real, etc.
• Can be specified by format: (ddd)ddd-dddd
5
SCHEMAS AND ATTRIBUTES
Relation schema
• A relation name R and a list of attributes: A1, A2, ..., An
• Denoted by R(A1, A2, ..., An)
Attribute Ai
• Name of a role in the relation schema R
• Associated with a domain dom(Ai)
• Attribute names do not repeat within relation schema, but domains
can repeat.
Degree (or arity) of a relation
• Number of attributes n in its relation schema
6
FORMALIZATION
Relation (or relation state)
• Set of n-tuples r = {t1, t2, ..., tm}
• Unordered, no duplicates
• Each n-tuple t
• Ordered list of n values t =<v1, v2, ..., vn>
• Each value vi, 1 ≤ i ≤ n, is an element of dom(Ai)
• Instance of relation schema R(A1, A2, A3, …, An)
• Finite subset of the Cartesian product of the domains defining R:
• rel(R) ⊆ (dom(A1) × dom(A2) × ... × dom(An))
Because of updates, relations are time-varying
• rel(R) is relation state at a given time
• Reflects only (and all) the valid tuples that represent a particular
state of the real world
8
RELATIONAL MODEL NOTATION
Symbolic notation
• Uppercase letters Q, R, S denote relation names
• Corresponding lowercase letters q, r, s denote corresponding
relation states
• Uppercase letters A, B, C, …, H denote attributes
• Attribute A can be qualified with the relation name R to which it
belongs using the dot notation, e.g., R.A
• Lower case letters t, u, v denote tuples
9
ALTERNATIVE DEFN OF RELATION
Tuple considered as a function from attributes to values
• tj : {A1, A2, A3, …, An} dom(A1) ∪ dom(A2) ∪ … ∪ dom(An)
• Use notation tj[Ai] or tj.Ai to refer to tuple’s value vi from dom(Ai)
• Similarly tj[Au, Aw, ..., Az] and tj.(Au, Aw, ..., Az) refer to the subtuple
of values <vu, vw, ..., vz> from tj for attributes Au, Aw, ..., Az
Therefore, tuple is a set of <attribute, value> pairs
e.g., for attendee (id, givenName, surname, company, dateOfBirth)
• t = <10483, John, Doe, IBM, 1978-11-05>
• t[id] = 10483, t[givenName] = John, t[surname] = Doe,
t[company] = IBM, t[dateOfBirth] = 1978-11-05
• t.id = 10483, t.givenName = John, t.surname = Doe,
t.company = IBM, t.dateOfBirth = 1978-11-05
• t = { <id, 10483>, <givenName, John>, <surname, Doe>,
<company, IBM>, <dateOfBirth, 1978-11-05> }
10
VALUES IN TUPLES
Each value in a tuple is atomic
• Flat (as opposed to nested) relational model
• Composite and multivalued attributes not allowed
• Historically relation is said to be in First normal form (1NF)
Composite attributes
• Split into simple component attributes
• e.g., Waterloo, Ontario treated as atomic or split into two attributes
to store Waterloo separately from Ontario
Multivalued attributes
• Must be represented by separate relations
• Recall: Director could be stored as attribute of FILM because only
one director per film assumed, but multiple characters in a film
implies that ROLE must have its own relation.
11
NULL VALUES
Assume each domain is augmented with a special NULL value
• Represent the values of attributes that may be unknown or may not
apply to a tuple
Interpretations for NULL values
• Nothing is known about the value
• Value exists but is (currently) not available
• Value undefined
• i.e., attribute does not apply to this tuple
• If an attribute for a tuple is mapped to NULL, cannot make any
assumptions about the value for that attribute (for that tuple)
• e.g., Ashley’s telephone number is NULL could mean
• Ashley doesn’t have a phone
• Ashley has a phone but we don’t know the number (perhaps withheld)
• Ashley has a phone that has no number
• Ashley may or may not have a phone, but regardless we don’t have a
number for Ashley
12
MEANING OF A RELATION
Assertion
• Each tuple in the relation interpreted as a fact.
• No other similar facts are of interest to the enterprise.
• e.g., a relation for Classlist includes only registered students and all
registered students are included in Classlist
• presence in list registered student
Predicate
• Values in each tuple interpreted as values that satisfy predicate
• e.g., Name of student having ID 83201556 is Lee Wong
13
LECTURE SUMMARY
Characteristics differentiate relations from ordinary tables or files
Schemas vs. instances (states)
Formal definitions for relations and tuples
Null values
14