DBMS Unit-2
DBMS Unit-2
Unit-2
Introduction to Relational Model:
Table or Relation: Collection of related records.
The columns of this relation are called Fields, Attributes or Domains. The rows are called Tuples
or Records.
Relational Algebra:
Selection and Projection:
Relational algebra includes operators to select rows from a relation (σ)and to project columns (π).
These operations allow us to manipulate data in a single relation. Con-sider the instance of the
Sailors relation shown in fig. 1, denoted as S2. We can retrieve rows corresponding to expert
sailors by using the σ operator. The expression
evaluates to the relation shown in fig. 2. The subscript rating>8 specifies the selection criterion to
be applied while retrieving tuples.
Fig. 2.
The selection operator σ specifies the tuples to retain through a selection condition. In general, the
selection condition is a boolean combination (i.e., an expression using the logical connectives ^
and) of terms that have the form attribute op constant or attribute1 op attribute2, where op is one
of the comparison operators <, <=, =, 6=,>=, or >. The reference to an attribute can be by position
(of the form .i or i) or by name (of the form .name or name). The schema of the result of a selection
is the schema of the input relation instance.
The projection operator π allows us to extract columns from a relation; for example, we can find
out all sailor names and ratings by using π. The expression
Fig. 3.
The subscript sname,rating specifies the fields to be retained; the other fields are `projected out.'
The schema of the result of a projection is determined by the fields that are projected in the obvious
way.
Suppose that we wanted to find out only the ages of sailors. The expression,
Set Operations:
21
22
Relational Calculus:
Relational calculus is an alternative to relational algebra. In contrast to the algebra, which is
procedural, the calculus is nonprocedural, or declarative, in that it allows us to describe the set
of answers without being explicit about how they should be computed.
The variant of the calculus that we present in detail is called the tuple relational calculus (TRC).
Variables in TRC take on tuples as values.
In another variant, called the domain relational calculus (DRC), the variables range over field
values.
23