Академический Документы
Профессиональный Документы
Культура Документы
Chapter 5-4
5.1 Relational Model Concepts
The relational Model of Data is based on the
mathematical concept of a relation (which is
based on the ideas of sets).
Chapter 5-5
Relational Model Concepts
The model was first proposed by Dr. E.F. Codd of
IBM in 1970 in the following paper:
"A Relational Model for Large Shared Data
Banks," Communications of the ACM, June 1970.
Chapter 5-6
Relational Model Concepts
INFORMAL DEFINITIONS
RELATION: A table of values
Chapter 5-7
I'm not sure I got that.
Please provide a lucid
example or I'll shoot
you with my finger.
Chapter 5-8
**
TABLE
column
Chapter 5-9
FORMAL DEFINITIONS
Each row in the EMPLOYEE table may be referred to as a
tuple in the table and would consist of four values, e.g.:
<1917, "M. R. Brent", "E21", "10/10/2003"> .
Chapter 5-10
The ROWS of a TABLE
Chapter 5-11
The ROWS of a TABLE
Chapter 5-12
The ROWS of a TABLE
Chapter 5-13
FORMAL DEFINITIONS
A Relation may be defined in multiple ways.
Chapter 5-14
Let's see if I've got that.
Employee is a table with
attributes, each of
which has a set of valid
values. Sounds like a
data type to me.
ZZZzzz.
Chapter 5-15
The ROWS of a TABLE
A row (tuple) is a set of values
In relational theory this set can be ordered or unordered
In practice the values are ordered within a row
Chapter 5-16
The ROWS of a TABLE
Chapter 5-17
Notes
Chapter 5-18
The COLUMNS of a TABLE
The columns of a table are also called attributes of the
relation.
The attribute help in interpreting the meaning of the values
The attribute names will be useful in searching the table.
For example: Find all EName where Dept=E21.
In plain English, that would be ________________________
Attributes
Chapter 5-19
The COLUMNS of a TABLE
A domain is a set of values.
Attributes
p. 127
Chapter 5-20
The COLUMNS of a TABLE
A domain is a set of values.
Chapter 5-21
The COLUMNS of a TABLE
A domain has a name, data type, and a format.
It also has constraints and a set of permissible operators
• e.g., user may see hot, warm, cold and the database stores
an integer value (representing degrees centigrade).
Chapter 5-24
The COLUMNS of a TABLE
A domain has a name, data type, and a format.
Consider the Hire_date column of the Employee table:
The domain name is denoted dom(Hire_date)
The domain data type is, say, character string
The domain format is mm/dd/yyyy
Chapter 5-25
The COLUMNS of a TABLE
A domain has a name, data type, and a format.
Consider the Hire_date column of the Employee table:
The domain name is denoted dom(Hire_date)
The domain data type is, say, character string
The domain format is mm/dd/yyyy
Chapter 5-26
The COLUMNS of a TABLE
A domain is a set of atomic values.
Atomic means that each value is indivisible as far as the
relational model is concerned
p. 127
Chapter 5-29
*
Notes
domain
attribute
n-tuple
degree of a relation
set
Chapter 5-30
I can't bear
to watch
Chapter 5-31
FORMAL DEFINITIONS
The relation is formed over the cartesian product of the sets;
each set has values from a domain; that domain is used in a
specific role which is conveyed by the attribute name.
For example, attribute EName is defined over the domain of
strings of 25 characters. The role these strings play in the
EMPLOYEE relation is that of the name of employees.
Formally,
Given R(A1, A2, .........., An)
r(R) ⊂ dom (A1) X dom (A2) X ....X dom(An)
R: schema of the relation
r of R: a specific "value" or population of R.
R is also called the intension of a relation
r is also called the extension of a relation page 129
Chapter 5-32
Example
Let S1 = {0,1}
Let S2 = {a,b,c}
Let R ⊂ S1 X S2
Chapter 5-33
Let's see if I've got that.
A populated table is
created from the domain
values of each attribute.
ZZZzzz.
Chapter 5-34
DEFINITION SUMMARY
Table Relation
Column Attribute/Domain
Row Tuple
Values in a column Domain
Table Definition Schema of a Relation
Populated Table Extension
Chapter 5-35
Tell them we're
working on populating
our table. Waiter, more
Java and croissants
please.
Chapter 5-36
To reiterate...
Chapter 5-37
Figure 5.1 The attributes and tuples of a
relation STUDENT.
Chapter 5-38
**
5.1.2 CHARACTERISTICS OF RELATIONS
Notation:
- We refer to component values of a tuple t by t[Ai] = vi
(the value of attribute Ai for tuple t).
Chapter 5-40
Figure 5.2 The relation STUDENT from
Figure 5.1 with a different order of tuples
Figure 5.1
Chapter 5-41
Figure 5.3 Two identical tuples when the
order of attributes and values is not part of
relation definition.
Chapter 5-42
And then he showed us this totally
cool example with two identical
tuples when the order of attributes
and values is not part of the relation
definition.
Chapter 5-43
Notes
Chapter 5-44
5.2 Relational Integrity
Constraints
Chapter 5-45
Key Constraints
Superkey of R:
Chapter 5-47
Key Constraints
Superkey of R: A set of attributes SK of R such that no
two tuples in any valid relation instance r(R) will have
the same value for SK. That is, for any distinct tuples t1
and t2 in r(R), t1[SK] ≠ t2[SK].
Chapter 5-49
Key Constraints
Key of R: A "minimal" superkey; that is, a superkey K
such that removal of any attribute from K results in a set
of attributes that is not a superkey.
Chapter 5-50
Key Constraints
Chapter 5-51
Key Constraints
Key of R: A "minimal" superkey; that is, a superkey K
such that removal of any attribute from K results in a set
of attributes that is not a superkey.
Chapter 5-52
Key Constraints
Chapter 5-53
I tell you Mike, a primary key is a
minimal superkey. Simple as that.
Say, where did everybody go?
Chapter 5-54
5.2 Relational Integrity
Constraints
Chapter 5-55
Entity Integrity
Relational Database Schema: A set S of relation schemas
that belong to the same database. S is the name of the
database.
S = {R1, R2, ..., Rn}
Entity Integrity: The primary key attributes PK of each
relation schema R in S cannot have null values in any tuple
of r(R). This is because primary key values are used to
identify the individual tuples.
t[PK] ≠ null for any tuple t in r(R)
Note: Other attributes of R may be similarly constrained
to disallow null values, even though they are not members
of the primary key.
Chapter 5-56
Entity Integrity
Relational Database Schema: A set S of relation schemas
that belong to the same database. S is the name of the
database.
S = {R1, R2, ..., Rn}
Schema S = ...
Chapter 5-57
Entity Integrity
Entity Integrity: The primary key attributes PK of each relation
schema R in S cannot have null values in any tuple of r(R). This is
because primary key values are used to identify the individual
tuples. t[PK] ≠ null for any tuple t in r(R)
Chapter 5-60
5.2 Relational Integrity
Constraints
Chapter 5-61
Referential Integrity
A constraint involving two relations (the previous
constraints involve a single relation).
Used to specify a relationship among tuples in two
relations: the referencing relation and the referenced
relation.
Tuples in the referencing relation R1 have attributes FK
(called foreign key attributes) that reference the primary
key attributes PK of the referenced relation R2. A tuple t1
in R1 is said to reference a tuple t2 in R2 if t1[FK] = t2[PK].
A referential integrity constraint can be displayed in a
relational database schema as a directed arc from R1.FK to
R2.
Chapter 5-62
Referential Integrity
referencing relation
foreign key
Chapter 5-63
Referential Integrity Constraint
Statement of the constraint
The value in the foreign key column (or
columns) FK of the the referencing relation R1
can be either:
(1) a value of an existing primary key value of
the corresponding primary key PK in the
referenced relation R2,, or..
(2) a null.
In case (2), the FK in R1 should not be a part of its
own primary key.
Chapter 5-64
Referential Integrity
These
values are
referencing relation
constrained
foreign key
Chapter 5-65
Chapter 5-66
Other Types of Constraints
Semantic Integrity Constraints:
- based on application semantics and cannot
be expressed by the model per se
- E.g., “the max. no. of hours per employee
for all projects he or she works on is 56 hrs
per week”
- A constraint specification language may
have to be used to express these
- SQL-99 allows triggers and ASSERTIONS
to allow for some of these
Chapter 5-67
Figure 5.5 Schema diagram for the
COMPANY relational database schema
Chapter 5-68
Figure 5.6
One possible
database
state for the
COMPANY
database
schema
p. 137
Chapter 5-69
Righttttttt...
Chapter 5-70
Figure 5.7 Referential integrity constraints
displayed on the COMPANY relational database
schema.
p. 139
Chapter 5-71
Righttttttt
again.
Chapter 5-72
5.3 Update Operations on Relations
INSERT a tuple.
DELETE a tuple.
MODIFY a tuple.
Chapter 5-73
Integrity constraints should not be violated by the update
operations.
Several update operations may have to be grouped
together.
Updates may propagate to cause other updates
automatically. This may be necessary to maintain integrity
constraints.
Chapter 5-74
Update Operations on Relations
In case of integrity violation, several actions can
be taken:
– Cancel the operation that causes the violation (REJECT
option)
– Perform the operation but inform the user of the
violation
– Trigger additional updates so the violation is corrected
(CASCADE option, SET NULL option)
– Execute a user-specified error-correction routine
Chapter 5-75
In-Class Exercise
(Taken from Exercise 5.15)
Consider the following relations for a database that keeps track of
student enrollment in courses and the books adopted for each
course:
STUDENT(SSN, Name, Major, Bdate)
COURSE(Course#, Cname, Dept)
ENROLL(SSN, Course#, Quarter, Grade)
BOOK_ADOPTION(Course#, Quarter, Book_ISBN)
TEXT(Book_ISBN, Book_Title, Publisher, Author)
Draw a relational schema diagram specifying the foreign keys
for this schema.
Chapter 5-76
Figure 5.8
The
AIRLINE
relational
database
schema.
Chapter 5-77
Notes
Chapter 5-78