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

DBMS Unit-2

Unit 2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

DBMS Unit-2

Unit 2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

18

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 model constraints over relations:


The constraints can be classified into 4 types as below:
1. Domain Constraints
2. Key Constraints
3. Entity Integrity Constraints.
4. Referential Integrity Constraints.
1. Domain Constraints
Domain constraints are the most elementary form of integrity constraints. They are tested easily
by the system whenever a new data item is entered into the database. Domain constraints specify
the set of possible values that may be associated with an attribute. Such constraints may also
prohibit the use of null values for particular attributes. The data types associated with domains
typically include standard numeric data types for integers A relation schema specifies the domain
of each field or column in the relation instance. These domain constraints in the schema specify
an important condition that each instance of the relation to satisfy: The values that appear in a
column must be drawn from the domain associated with that column. Thus the domain of a field
is essentially the type of that field.
2. Key Constraints
A key constraint is a statement that a certain minimal subset of the fields of a relation is a unique
identifier for a tuple. Example:
The ‘students’ relation and the constraint that no 2 students have the same student id (sid).
3. Entity Integrity Constraints
This states that no primary key value can be null. The primary key value is used to identify
individual tuples in a relation. Having null values for the primary key implies that we cannot
identify some tuples. NOTE: Key Constraints, Entity Integrity Constraints are specified on
individual relations. PRIMARY KEYS comes under this.
4. Referential Integrity Constraints
The Referential Integrity Constraint is specified between 2 relations and is used to maintain the
consistency among tuples of the 2 relations. Informally, the referential integrity constraint states
that ‘a tuple in 1 relation that refers to another relation must refer to an existing tuple in that
relation. We can diagrammatically display the referential integrity constraints by drawing a
directed arc from each foreign key to the relation it references. The arrow head may point to the
primary key of the referenced relation.
19

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. 1. Instance S1 of sailors

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

evaluates to the relation shown in Figure 3.


20

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,

evaluates to the relation,

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

Tuple Relational Calculus:


24
25

Domain Relational Calculus:


26

You might also like