0% found this document useful (0 votes)
13 views

Chapter 6

Uploaded by

Abinet Arba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Chapter 6

Uploaded by

Abinet Arba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CHAPTER SIX

The Relational Data Model and the Relational


Algebra
Contents
The Relational Model Concepts
The Relational Constraints and Relational
Database Schemas
The Relational Operations

1
Relational Model Concepts
 The relational model represents the database as
a collection of relations. Informally, each
relation resembles a table of values or, to some
extent, a "flat" file of records.
 In the formal relational model terminology,
 row is called a tuple,
 column header is called an attribute, and
 the table is called a relation.
 The data type describing the types of values
that can appear in each column is called a
domain.

2
Example STUDENT relation table

3
Domains, Attributes, Tuples, and
Relations
 A domain D is a set of atomic values.
 By atomic we mean that each value in the
domain is indivisible as far as the formal
relational model is concerned.
 A common method of specifying a domain is
to specify a data type from which the data
values forming the domain are drawn.
 It is also useful to specify a name for the
domain, to help in interpreting its values.

4
Some examples of domains follow:
 USA_phone_numbers: The set of 10-digit
phone numbers valid in the United States.
 Names: The set of character strings that
represent names of persons.
 Employee_ages. Possible ages of employees
in a company; each must be an integer value
between 15 and 80.

5
Characteristics of Relations
A.Ordering of Tuples in a Relation
 A relation is defined as a set of tuples.
Mathematically, elements of a set have no order
among them; hence tuples in a relation do not have
any particular order.
 Tuple ordering is not part of a relation definition,
because a relation attempts to represent facts at a
logical or abstract level.
 example, tuples in the STUDENT relation could
be logically ordered by values of Name, SSN, Age,
or some other attribute.

6
B.Values & NULLs in the Tuples
 Each value in a tuple is an atomic value; that is, it
is not divisible into components within the
framework of the basic relational model. Hence,
composite and multivalued attributes are not
allowed.
 Much of the theory behind the relational model was
developed with this assumption in mind, which is
called the first normal form assumption.
 Hence, multivalued attributes must be represented
by separate relations, and composite attributes are
represented only by their simple component
attributes.

7
 An important concept is that of NULL values, which are used
to represent the values of attributes that may be unknown or
may not apply to a tuple. A special value, called NULL, is
used in these cases.
 For example, in Figure 1, some STUDENT tuples have
NULL for their office phones because they do not have an
office (that is, office phone does not apply to these students).
 In general, we can have several meanings for NULL values,
such as value unknown, value exists but is not available,
or attribute does not apply to this tuple (also known as value
undefined).

8
C. Interpretation of a Relation
 The relation schema can be interpreted as a declaration or a
type of declaration. For example, the schema of the
STUDENT relation asserts that, in general, a student entity
has a Name, SSN, Home Phone, Address, Office Phone,
Age, and GPA. Each tuple in the relation can then be
interpreted as a fact or a particular instance of the
declaration.
 Each tuple in the relation can then be interpreted as a fact or
a particular instance of the assertion. For example, the first
tuple in Figure1 asserts the fact that there is a STUDENT
whose Name is Benjamin Bayer, Ssn is 305-61-2435, Age is
19, and so on.

9
Relational Constraints and Relational
Database Schemas
 There are generally many restrictions or constraints on the
actual values in a database state.
 Constraints on databases can generally be divided into
three main categories:
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 schemas of
the data model, typically by specifying them in the DDL
(data definition language).We call these schema-based
constraints or explicit constraints.
3. Constraints that cannot be directly expressed in the
schemas of the data model, and hence must be expressed
and enforced by the application programs. We call these
application-based or semantic constraints or business
rules.
. 10
The schema-based constraints include domain constraints,
key constraints, constraints on NULLs, entity integrity
constraints, and referential integrity constraints.

Domain Constraints
 Domain constraints specify that the value of each attribute
A must be an atomic value from the domain dom(A). The
data types associated with domains typically include
standard numeric data types for integers and real numbers.
Characters, fixed-length strings, and variable-length
strings are also available
Key Constraints and Constraints on Null
 A relation is defined as a set of tuples. By definition, all
elements of a set are distinct; hence, all tuples in a relation
must also be distinct.
 This means that no two tuples can have the same
combination of values for all their attributes.

11
Update Operations and Dealing
with Constraint Violations
 The operations of the relational model can be
categorized into retrievals and updates.
 They insert new data, delete old data,or modify existing
data records.
The Insert Operation
 Insert is used to insert one or more new tuples in a
relation.
The Delete Operation
• Delete is used to delete tuples.
The Update Operation
• Update (or Modify) is used to change the values of
some attributes in existing tuples.

12
Basic Relational Algebra
Operations

 The SELECT Operation


 The PROJECT Operation
 Sequences of Operations and the RENAME
Operation
 Set Theoretic Operations
 The JOIN Operation
 A Complete Set of Relational Algebra
Operations
 The DIVISION Operation

13

You might also like