0% found this document useful (0 votes)
87 views26 pages

Chapter 02 Part A

The document discusses various relational algebra operations including selection, projection, union, difference, cartesian product, join, and semi-join. Examples are provided to demonstrate how each operation works by taking one or two relations as input and producing a single relation as output.
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)
87 views26 pages

Chapter 02 Part A

The document discusses various relational algebra operations including selection, projection, union, difference, cartesian product, join, and semi-join. Examples are provided to demonstrate how each operation works by taking one or two relations as input and producing a single relation as output.
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/ 26

CSE 4125: Distributed Database

Systems
Chapter – 2: Part A

Review of Databases and Computer


Networks

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 1


Review of Databases

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 2


The Relational Model

Relations: Data stored in tables.


Attributes: Fixed number of columns.
Tuples: Dynamic number of rows.
Grade: Number of attributes.
Cardinality: Number of tuples.

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 3


12/23/2020 G. M. Shahariar Shibli | CSE, AUST 4
Relational Schema
 Representation of a relation.
 Name of the relation and the attributes
appearing in it.

Example:
𝐸𝑀𝑃 (𝐸𝑀𝑃𝑁𝑈𝑀, 𝑁𝐴𝑀𝐸, 𝐴𝐺𝐸, 𝐷𝐸𝑃𝑇𝑁𝑈𝑀)

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 5


KEYS
Subset of the attributes whose values are unique.

Example:

𝐸𝑀𝑃 (𝐸𝑀𝑃𝑁𝑈𝑀, 𝑁𝐴𝑀𝐸, 𝐴𝐺𝐸, 𝐷𝐸𝑃𝑇𝑁𝑈𝑀)

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 6


Relational Algebra
A collection of operations.
Takes relation(s) as input.
Produces one relation as result.
Two types –
i. Unary: 1 input, 1 result
ii. Binary: 2 inputs, 1 result

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 7


Unary: Selection
Example: SL A= a R
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 8


Unary: Selection
Example: SL A= a R
R S T Result

A B C

a 1 a a 1 a 1 a 1 a 1 a

b 1 b a 3 f 3 b 1 a 1 d

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 9


Unary: Projection
Example: PJ A,B R
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 10


Unary: Projection
Example: PJ A,B R
R S T Result

A B C

a 1 a a 1 a 1 a 1 a 1

b 1 b a 3 f 3 b 1 b 1

a 1 d 3 c 2 b 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 11


Binary: Union
Example: R UN S
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 12


Binary: Union
Example: R UN S
R S T Result

A B C
a 1 a
a 1 a a 1 a 1 a 1
b 1 b
b 1 b a 3 f 3 b 1 a 1 d

a 1 d 3 c 2 b 2 f
a 3 f
b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 13


Binary: Difference
Example: R DF S
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 14


Binary: Difference
Example: R DF S
R S T Result

A B C
b 1 b
a 1 a a 1 a 1 a 1
a 1 d
b 1 b a 3 f 3 b 1
b 2 f
a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 15


Binary: Cartesian Product
Example: R CP S
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 16


Binary: Cartesian Product
Example: R CP S
R S T Result

A B C
a 1 a a 1 a
a 1 a a 1 a 1 a 1 b 1 b a 1 a

b 1 b a 3 f 3 b 1 a 1 d a 1 a
b 2 f a 1 a
a 1 d 3 c 2
a 1 a a 3 f
b 2 f 1 d 4 b 1 b a 3 f
a 1 d a 3 f
2 a 3
b 2 f a 3 f

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 17


Binary: Join
Example: R JNR.C=T.C T
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 18


Binary: Join
Example: R JNR.C=T.C T
R S T Result

A B C
a 1 a 1 a 1
a 1 a a 1 a 1 a 1
a 1 a 2 a 3
b 1 b a 3 f 3 b 1 b 1 b 3 b 1

a 1 d 3 c 2 a 1 d 1 d 4

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 19


Binary: Semi-join
Example: R SJR.C=T.C T
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 20


Binary: Semi-join
Example: R SJR.C=T.C T
R S T Result

A B C

a 1 a a 1 a
a 1 a 1 a 1
b 1 b
b 1 b a 3 f 3 b 1
a 1 d
a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 21


Binary: Natural Join
Example: R NJN T
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 22


Binary: Natural Join
Example: R NJN T
R S T Result

A B C

a 1 a a 1 a 1 a 1 a 1 a 1

b 1 b a 3 f 3 b 1 a 1 d 4

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 23


Binary: Natural Semi-join
Example: R NSJ T
R S T Result

A B C

a 1 a a 1 a 1 a 1

b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 24


Binary: Natural Semi-join
Example: R NSJ T
R S T Result

A B C
a 1 a
a 1 a a 1 a 1 a 1
a 1 d
b 1 b a 3 f 3 b 1

a 1 d 3 c 2

b 2 f 1 d 4

2 a 3

12/23/2020 G. M. Shahariar Shibli | CSE, AUST 25


Application, Program and Query
 Database Applications:
Sequence of operations requested by end users (not a
programmer).
Examples: read.

 Database Programs:
Implementation of the application.

Query:
An expression in a suitable language.
Defines a portion of data contained in DB.
12/23/2020 G. M. Shahariar Shibli | CSE, AUST 26

You might also like