You are on page 1of 38

Chapter 6

• The Relational Algebra


and
Relational Calculus
The Relational Algebra

• The relation algebra is a procedure query language.


.

The relation algebra consists of set of operations


that has one or two relations as input and gives
a new relation.
.
Some of the operations in the relation algebra are
selection ( )
projection ( ) unary operations

set union (  )
set difference(-) set operations
intersection (  )
Cartesian product ( x )

natural join ( )
division (  ) binary operation
Selection Operation
• When we want to get only some of the tuples
from a relation satisfying a given condition,
we can use this operation
Example for selection
s.no Sname Class Att.percentage

1001 RAM M.Tech 88

1002 KRISHAN M.C.A 91

1003 GULSHAN M.C.A 95

1004 SUBHANI M.Tech 96

1005 SUGUNA B.Tech 100

1006 PREETHI B.Tech 91


.

If we want to get all the details of the students


studying M.C.A, then we can perform the
selection operation.

 class=M.C.A (STUDENT)
1002 KRISHAN M.C.A 91

1003 GULSHAN M.C.A 95


projection( ) operation
• This operation keeps certain columns
(attributes) from a relation and discards the
other columns.
pSname,class (STUDENT)
RAM M.Tech
KRISHAN M.C.A
GULSHAN M.C.A
SUBHANI M.Tech
SUGUNA B.Tech
PREETHI B.Tech
.

• We can also combine the selection and


projection operations.
• If we want to get the sname and attendence
percentage for students studying B.tech., then
we can following the operation.
 sname,att.percentage ( class=M.C.A (STUDENT))

SUGUNA 100
PREETHI 91
Union operation
• It is denoted by 
• Union of R and S is denoted by R  S.
• Duplicate tuples are eliminated
• R and S must have same number of
attributes.
• It is the set of tuples with which are
either in R or in S or both
.

• Let R and S be two relations of news paper


readers.
• R is the set of readers who read “Eenadu” paper
and
• S is the set of readers who read “Hindu” paper
R NAME S NAME R  S NAME
KRISHNA KRISHNA KRISHNA
SUBHANI PREETHI
SUBHANI
SUGUNA GULSHAN
SUGUNA
PREETHI
GULSHAN
Intersection operation
• It is denoted by R  S
• It is the set of tuples which are both in R and S

• R  S NAME
KRISHNA
Set difference
• It is denoted by R-S.
• It is the set of tuples which are there in R but
not in S.
• R-S NAME

SUBHANI

SUGUNA
CARTESIAN PRODUCT

if R has nR tuples (denoted as |


R| = nR ), and S has nS tuples,
then R x S will have
nR * nS tuples.
.
Let R SNO SNAME S CLASS CLASS
CODE NAME
1001 RAM
1 M.Tech
1002 KRISHNA

1003 GULSHA 2 M.C.A


N
1004 SUBHANI
3 B.Tech
1005 SUGUNA
sno sname Class code Class name
1001 RAM 1 M.Tech
1001 RAM 2 M.C.A
1001 RAM 3 B.Tech
1002 KRISHNA 1 M.Tech
1002 KRISHNA 2 M.C.A
1002 KRISHNA 3 B.Tech
1003 GULSHAN 1 M.Tech
1003 GULSHAN 2 M.C.A
1003 GULSHAN 3 B.Tech
1004 SUBHANI 1 M.Tech
1004 SUBHANI 2 M.C.A
1004 SUBHANI 3 B.Tech
1005 SUGUNA 1 M.Tech
1005 SUGUNA 2 M.C.A
1005 SUGUNA 3 B.Tech
.
• Generally, CROSS PRODUCT is not a
meaningful operation
JOIN OPERATION
The general form of a join operation
on two relations R and S:
R <join condition> S
.
• It is applicable only when there is atleast one
attribute common in R and S
.
Let R SNO SNAME CLASS S CLASS CLASS
CODE CODE NAME
1001 RAM 1
1 M.Tech
1002 KRISHNA 1

1003 GULSHAN 2 2 M.C.A

1004 SUBHANI 3
3 B.Tech
1005 SUGUNA 3
.

R <R.CLASSCODE=S.CLASSCODE> S
.
SNO SNAME CLASS CLASS
CODE NAME
1001 RAM 1 M.Tech

1002 KRISHNA 1 M.Tech

1003 GULSHAN 2 M.C.A

1004 SUBHANI 3 B.Tech

1005 SUGUNA 3 B.Tech


Chapter-12

DDBMS
DDBMS
• In DDBMS, the database is stored on several
computers.
• The computers in a distributed system
communicate with one another through
various communication media such as
telephone lines.
• The computers in distributed system are
referred by sites or nodes.
Types of DDBMS
1. Homogeneous DDBMS

2. Heterogeneous DDBMS
Homogeneous DDBMS
In this, all sites have identical DBMS s/w

Window
Site 5 Unix
Oracle Site 1
Oracle
Window
Site 4 Communications
network

Oracle
Site 3 Site 2
Linux Oracle Linux Oracle
Heterogeneous DDBMS
In this, different sites may use different DBMS s/w

Object Unix Relational


Oriented Site 5 Unix
Site 1
Hierarchical
Window
Site 4 Communications
network

Network
Object DBMS
Oriented Site 3 Site 2 Relational
Linux Linux
Distributed data storage
• Consider a relation R that is to be stored in the
database.
• There are two approaches for storing this
relation in the DDBMS.
• These are
1. replication
2. fragmentation
Replication
• The system maintains several identical
replicas(copies) of the relation and stores each
replica at different site.
• If a relation R is replicated, a copy of relation R
is stored in two or more sites.
• In extreme case, a copy is stored in every site
in the system , which is called as full
replication
Advantage of replication
• Availability:
if one of the sites containing relation R fails,
then the relation R can be found in another
site. So the system can continue to process.
Disadvantage of replication
Increased overhead on update
Fragmentation
• The system partitions the relation into several
fragments and stores each fragment at a
different sites
• If relation R is fragmented, then R is divided
into a number of fragments r1,r2,…rn.
• These fragments contain sufficient
information to allow reconstruction of the
original relation R
Types of Fragmentation
1.Horizontal Fragmentation

2.Vertical Fragmentation
Horizontal fragmentation
• In horizontal fragmentation, a relation R is
partitioned into a number of subsets r1,r2,…r3.
• Each tuple of relation R must belong to at least
one of the fragments.
• In general, a horizontal fragment can be defined
as a selection on the global relation ‘R’.
• The predicate p is used to construct fragment ri
ri = p (R)
we reconstruct the relation ‘r’ by taking the union
of all fragments.
r1  r2  r3  ……….  rn
Vertical fragmentation
In this , a relation R is split into number of
subsets of attributes.
here,
each vertical fragment ri is defined by
ri =  Ri(r)
We reconstruct relation ‘R’ by taking the join
i.e.,
R= r1 r2 ……… rn
Advantages of DDBMS
1. Sharing data:
using distributed system, users at one site are
able to access the data residing at other site.
2. availability:
if one of the sites containing relation R fails,
then the relation R can be found in another
site. So the system can continue to process.
Disadvantage of DDBMS
• 1. s/w development cost.

• 2. greater potential bugs.

• 3. increased processing overhead

You might also like