Unit 4 - Relational Algebra Flashcards

1
Q

What are the inputs and outputs of a query?

A

Both the inputs and outputs of a query are relations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Operators are either unary or binary. What’s the diff?

A

Unary accepts ONE relation as input; binary accepts TWO relations as input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the unary operators?

A

Selection, projection, rename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does selection Operator (sigma) return?

A

Returns a subset of tuples (rows) that satisfies some condition(s)
It’s like FILTERING a spreadsheet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the order for selection operator?

A

sigma <attribute> <comparison> <constant> (Relation R)</constant></comparison></attribute>

comparison operator can be
>, <, =, >=, <=, !=

can also compare two attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can you have more than one selection condition when using selection operator?

A

Yes. Can link using boolean operators: AND, OR, NOT
e.g., GPA <= 3.6 AND Age = 20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Sigma <C2> ( Sigma <C1> ( R ) ) What's the order of execution?</C1></C2>

A

From the inside out
Select tuples from R that match C1, then on that result filter for C2

(here, you get same result either way)
(which is same as, sigma <C1>)</C1>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does projection operator (Pi) return?

A

Only the selected columns (fields/attributes)
Pi <Attribute 1, Attribute 4,..> (R)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does renaming operator (rho) return?

A

Allows us to rename,
1. the output relation (from other operators)
2. certain attributes in the output relation

can also make a copy of a relation and rename that
rho <S> (R)
becomes just (S) which is a copy of (R)</S>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What must be true of the inputs for binary operators?

A

Input relations MUST BE COMPATIBLE:
1. SAME NUMBER of attributes
2. same attribute NAMES and DATA TYPES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

R Union S returns what?

A

A relation containing ALL tuples that occur in R and ALL tuples that occur in S
(duplicate tuples are removed)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

R Intersection S returns what?

A

A relation containing only the tuples in BOTH R and S

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

R Difference S returns what?

A

A relation containing all tuples in R but not in S.
If a relation is R is also in S, it is removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does Cross-Product (Cartesian Product) do? Relation S X Relation S = ?

A

A relation where all fields of R are followed by all fields of S
Forms all possible combos of R X S

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does JOIN operator do?

A

Joins a group of tables
Establishes connections between data records in different tables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the two types of JOIN operator?

A
  1. Natural join
  2. Theta (or Equi) Join
17
Q

What does natural join do? R natural join S = ?

A

First, R X S (must have 1+ common attribute(s))
Assume attribute C is the common attribute.
ONLY keep values where R.C = S.C
Remove the duplicate attribute (R.C and S.C just become C again)
ALL other attributes are added

18
Q

What does Theta/Equi join do?

A

Joins two relations/tables based on conditions or relationships between attributes

E.g., R < theta join > (R.Ai = S.Bj) (S)
is the same as saying, do R X S, then filter for all values where R.Ai = S.Bj.

19
Q

When would you use Theta/Equi join?

A

When you have some condition that must be met.

E.g., if you DON’T have the same name attribute, but values are the same, you can say,
Prof <theta> (Pid = id) (Lectures)
In Prof table, it's "Pid" but in Lecture table, it's "id" (but same values) so you can just make them equal in a theta join</theta>

20
Q

What are the four types of join within Natural join and Theta(Equi) join?

A

Inner, Left-join, Right-join, Outer

Inner - get records where join condition met, ONLY.
Left - get everything from the left, and only the records that meet the join condition on the right. (‘NULL’ if A doesn’t have match)
Right - opposite ^
Outer - get all records from left and right. ‘NULL’ if no match from the other side.

21
Q

Division operation. R divided by S returns what?
(S must be a subset of R)

A

Gives us records in R that are associated with all records in S (doesn’t include records of S in result)

22
Q

If you want to use union, intersection, and difference, what MUST you have?

A

SAME number of attributes, same names, and same datatypes!

23
Q
A