Professional Documents
Culture Documents
Module 2.1
The Relational Data Model and Relational Database
Constraints
Prof. Mahesh T
R
Dept. of CSE 1
OUTLINE
The Relational Data Model and Relational Database
Constraints
⚫ Relational Model Concepts
⚫ Update operations, transactions, and dealing with constraint
violations
⚫ Characteristics Of Relations
⚫ Domain Constraint
⚫ Key Constraint
⚫ Entity Integrity
⚫ Referential Integrity
⚫ Update Operations on Relations
2
RELATIONAL MODEL CONCEPTS
3
RELATIONAL MODEL CONCEPTS
Informal Definitions
• Informally, a relation looks like a table of values.
• A relation typically contains a set of rows.
• The data elements in each row represent certain facts that
correspond to a real-world entity or relationship
In the formal model, rows are called tuples
• Each column has a column header that gives an indication of the
meaning of the data items in that column
In the formal model, the column header is called an attribute name
(or just attribute)
4
RELATIONAL MODEL CONCEPTS
5
RELATIONAL MODEL CONCEPTS
Key of a Relation:
Each row has a value of a data item (or set of items) that
uniquely identifies that row in the table
Called the key
6
RELATIONAL MODEL CONCEPTS
7
RELATIONAL MODEL CONCEPTS
9
RELATIONAL MODEL CONCEPTS
10
RELATIONAL MODEL CONCEPTS
Formally,
Given R(A1, A2, .........., An)
r(R) ⊂ dom (A1) X dom (A2) X ....X dom(An)
R(A1, A2, …, An) is the schema of the relation
R is the name of the relation
A1, A2, …, An are the attributes of the relation
r(R): a specific state (or "value" or “population”) of relation R –
this is a set of tuples (rows)
r(R) = {t1, t2, …, tm} where each ti is an n-tuple
ti = <v1, v2, …, vn> where each vj element-of dom(Aj)
11
RELATIONAL MODEL CONCEPTS
12
RELATIONAL MODEL CONCEPTS
13
CHARACTERISTICS OF RELATIONS
We will consider the attributes in R(A1, A2, ..., An) and the values in t=<v1, v2, ...,
vn> to be ordered .
(However, a more general alternative definition of relation does not require this
ordering).
14
CHARACTERISTICS OF RELATIONS
Each value in a tuple is an atomic value; that is, it is not divisible into components
Hence, composite and multivalued attributes (see Chapter 3) are not allowed. This
model is sometimes called the flat relational model. Much of the theory behind the
relational model was developed with this assumption in mind, which is called the first
normal form assumption.
A special null value is used to represent values that are unknown or inapplicable to
certain tuples.
Eg., some STUDENT tuples have NULL for their office phones because they do not have
an office
15
RELATIONAL MODEL NOTATION
16
RELATIONAL MODEL CONSTRAINTS
AND RELATIONAL DATABASE SCHEMAS
1. Constraints that are inherent in the data model. We call these inherent
model-based constraints or implicit constraints.
2. Constraints that can be directly expressed in the schemas of the data model, typically
by specifying them in the DDL (data definition language,
We call these schema-based constraints or explicit constraints.
17
RELATIONAL MODEL CONSTRAINTS
AND RELATIONAL DATABASE SCHEMAS
Domain Constraints
Domain constraints specify that within each tuple, the value of
each attribute A must be an atomic value from the domain
dom(A).
In general, a relation schema may have more than one key. In this
case, each of the
keys is called a candidate key. For example, the CAR relation
has two candidate keys: License_number and
Engine_serial_number.
It is common to designate one of the candidate keys as the
primary key of the relation. This is the candidate
key whose values are used to identify tuples in the relation.
20
RELATIONAL DATABASES AND RELATIONAL
DATABASE SCHEMAS
21
RELATIONAL DATABASES AND RELATIONAL
DATABASE SCHEMAS
Company Database Schema
22
ENTITY INTEGRITY, REFERENTIAL INTEGRITY, AND
FOREIGN KEYS
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)
If PK has several attributes, null is not allowed in any of these
attributes
23
ENTITY INTEGRITY, REFERENTIAL INTEGRITY, AND
FOREIGN KEYS
1. The attributes in FK have the same domain(s) as the primary key attributes
PK of R2; the attributes FK are said to reference or refer to the relation R2.
2. A value of FK in a tuple t1 of the current state r1(R1) either occurs as a value
of PK for some tuple t2 in the current state r2(R2) or is NULL. In the former
case, we have t1[FK]
24
ENTITY INTEGRITY, REFERENTIAL INTEGRITY, AND
FOREIGN KEYS
25
UPDATE OPERATIONS, TRANSACTIONS,
AND DEALING WITH CONSTRAINT VIOLATIONS
26
UPDATE OPERATIONS, TRANSACTIONS,
AND DEALING WITH CONSTRAINT VIOLATIONS
30
SUMMARY
31