2.2 Intro to Relational Model/2

Module Outline

This section will cover Relational Algebra and its operators in great depth.

Basic Properties of Relations

A relation is a set. So, the order of tuples or rows don’t matter.

  • The order of tuples is inconsequential
A B
a1 b1
a1 b2
a2 b1
a2 b2
  • All rows/tuples must be distinct. Duplicate rows are not allowed.
A B A B
a1 b1 invalid a1 b1
a1 b2 a1 b2
a1 b2 a2 b1
a2 b1 a2 b2
a2 b1

Select Operation

Select Operation is used to select a subset of rows from a relational instance which satisfy a condition. This takes few rows horizontally.

  • It is denoted with Sigma. IMage

Project Operation

Project Operation is used to take out some columns, - It is denoted with pi.

Image

Union of two relations

If two relations have identical set of attributes, then we take their union.

Put images or illustrations

Set difference

What is present in set R and not in Set S, and take out similar ones which are in S and R.

Set Intersection

Tuples or rows which are present in both R and S.

Cartesian Product

Cartesian Product is used to combine and scale the two relations. If we do projection on the cartesian product, we get back the original relation.

Issue with cartesian product if two relations have same column name.

Take a screenshot of the ppt slide to demonstrate.

Renaming a table. -: Learn more about this topic.

Composition of Operations

We can build expressions using multiple operations. Ex : Sigma (A=C) = C(rXs)

Natural Join

Let r and s be the relations on schema R and S respectively. The natural join of relations R and S is a relation on schema R U S . - Consider each pair of tuples tr from r and ts from s. - If ts and tr have the same value on each attributes in R intersection S, that is if there is an attribute which is common b/w R and S, then tuples which have identical values on that attribute will be taken in the natural join. In contrast in Cartesian Product we will take all the values.

This is a very important and powerful operation.

Show the example as shown in the PPT slides.

Aggregate Operators

We take a relation and based on one or more columns and conditions, we do an aggregation. The type of that column should be possible to perform that certain aggregate operation.

Aggregate Operations :

  • SUM
  • AVG
  • MIN
  • MAX

These operations are performed on columns and generally produce a numerical value. While Relational Operators take in relations and produce a relation as an output.