presentation

17

Upload: ayesha-ch

Post on 11-Apr-2017

91 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Presentation
Page 2: Presentation

Topic: Relational Algebra:

1)unary operation 2)Binary operation

Presented By: Group #03

Members: 1 : Sania Shokat 2 : Ayesha Ramzan 3 : Arooj fatima 4 : Mehwish Aslam

Page 3: Presentation

Table of contents:Relational Algebra:

Unary Operationo Selectiono projection

Binary Operationo Union o Set Difference o Cartesian Product

Page 4: Presentation

Relational Algebra:

Relational Algebra is a procedural language that processes one or more relations to define another relation without changingoriginal relation.

Page 5: Presentation

1.Selection Operation: o Acts like a filter on a relation.o Return only a certain number of tuples.o Selects the tuple using a condition.o Resulting relation has the same degree as the original relation.

Unary Relation:

o Involve only one relation.

Page 6: Presentation

Examples: Assume a relation EMP has the following tuples:

Name Office Dept RankAhmed 220 CS lecturerbaber 140 Ecno AssistantSaleem 160 CS Associatemirza 500 FIn Associate

Page 7: Presentation

σ dept=‘cs’(EMP)

Result:.

Name Office Dept RankAli 400 CS AssistantSaleem 160 CS Associate

Question: Select only those employees who are in CS department.

Page 8: Presentation

2. Projection:

o Limit the attribute returned from the original relation.o Projection operator is pi π .o Resulting table has the same number of tuples as the original.

Example: Assume the EMP relation

Name Office Dept RankAhmed 220 CS lecturerbaber 140 Ecno AssistantSaleem 160 CS Associatemirza 500 FIn Associate

Page 9: Presentation

Question:Display the names and departments of the all employees working inCS department:

π name,Dept (σ dept=‘cs’(EMP) )

Result:Name DeptAhmed CSSaleem CS

Page 10: Presentation

o Operations which involve pairs of relations.

o Uses two operations as input and produce a new relation as output.

o Types:

1. Union

2. Set Difference

3. Cartesian Product

Binary Operations:

Page 11: Presentation

o Union operation of two relations combines the tuples of both relations to produce a third relation.

o Denoted by U.

1.Union:

Page 12: Presentation

X

Y Z

1 A 10

2 B 20

3 C 30

X Y Z

1 A 10

4 D 40

5 E 50

X Y Z

1 A 10

2 B 20

3 C 30

4 D 40

5 E 50

Table A Table B A UNION B

Example: (A U B)

Two relations A and B are combined together by using union operator.

Page 13: Presentation

2. Set Difference

o Works on two relations.

o Produces a third relation that contains the tuples that occur

in the first relation but not in second.

Page 14: Presentation

Example: There are two relations A and B.

X Y Z

1 A 10

2 B 20

3 C 30

X Y Z

1 A 10

4 D 40

5 E 50

X Y Z

2 B 20

3 C 30

X Y Z

4 D 40

5 E 50

Table B A - B B - ATable A

Page 15: Presentation

3. Cartesian Product :

o Works on two relations.

o Concatenates every tuple in one relation with every tuple second.

o Also called cross product.

o Product is denoted by a × b.

Page 16: Presentation

Example:

X Y Z

1 A 10

2 B 20

3 C 30

Table A

X Y Z

1 A 10

4 D 40

5 E 50

X1

Y1

Z1

X2

Y2

Z2

1 A 10

1 A 10

1 A 10

4 D 40

1 A 10

5 E 50

2 B 20

1 A 10

2 B 20

4 D 40

2 B 20

5 E 50

3 C 30

1 A 10

3 C 30

4 D 40

3 C 30

5 A 50

Table B

Table A × B

Page 17: Presentation