L.05 Flashcards

Continuing With Relational Algebra

1
Q

What is the purpose of Relational Algebra (RA)?

A

It is a formal mathematical language used to define queries over relational models.

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

What is the result of applying an RA operation on a relation?

A

The result is always a new relation, making RA a closed algebra.

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

What does the Selection (𝞂) operation do?

A

It filters rows in a relation based on a specified condition.
Example:
Find employees in department 4:
𝞂DNO=4(EMPLOYEE)

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

What does the Projection (π) operation do?

A

It selects specific columns (attributes) from a relation and removes duplicates.
Example:
List first names, last names, and salaries:
πLNAME,FNAME,SALARY(EMPLOYEE)

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

What is Generalized Projection in RA?

A

It allows functions on attributes rather than selecting them directly.
Example:
Compute yearly salary:
πLNAME,FNAME,12 * SALARY(EMPLOYEE)

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

What is the purpose of Assignment (←) in RA?

A

It stores intermediate results for complex RA operations.
DEP5_EMPS ← 𝞂DNO=5(EMPLOYEE)
πLNAME,FNAME,SALARY(DEP5_EMPS)

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

What does the Renaming (ρ) operation do?

A

It renames the relation and its attributes for better readability.
ρYEMPLOYEE(LNAME, FNAME, YSALARY (πLNAME,FNAME,12 * SALARY(EMPLOYEE))

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

What are the set operations in RA?

A

Union (∪): Combines unique tuples from both relations.
Intersection (∩): Returns tuples present in both relations.
Difference (-): Returns tuples in one relation but not in the other.

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

What are the conditions for type compatibility between two relations in RA?

A

1) They must have the same number of attributes.
2) The domains of corresponding attributes must match.

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

What does the Cartesian Product (×) operation do?

A

It pairs every tuple in one relation with every tuple in another, creating a new relation.
Example:
Ranks × Suits → Creates all possible playing cards.

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

Why is Join (⨝) commonly used instead of Cartesian Product (×) + Selection (𝞂)?

A

Because Join directly combines related tuples without creating unnecessary combinations.
DEPT_MGR ← DEPARTMENT ⨝ MGRSSN=SSN EMPLOYEE

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

What is an Equijoin?

A

A Join where the condition consists only of equality (=).
R ⨝ R.a = S.b S

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

What is a Natural Join ( or ⨝)* in RA?

A

A special case of Equijoin where the join is done on all attributes with the same name in both relations.
R(A,B,C,D) * S(C,D,E)

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

What problem does an Outer Join solve?

A

It preserves unmatched tuples in one or both relations instead of discarding them.
Types:
Left Outer Join (⟕): Keeps all tuples from the left relation.
Right Outer Join (⟖): Keeps all tuples from the right relation.
Full Outer Join (⟗): Keeps all tuples from both relations.

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

What are Aggregate Functions in RA?

A

Functions that summarize values over multiple tuples.
Examples:
ℱSUM Salary(EMPLOYEE) → Total salary of all employees.
ℱMAX Salary(EMPLOYEE) → Maximum salary.
ℱCOUNT Ssn(EMPLOYEE) → Number of employees.

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

How do we apply aggregation with grouping in RA?

A

Use grouping attributes before applying the aggregate function.
Example:
DNO ℱCOUNT Ssn, AVERAGE Salary(EMPLOYEE)

(Groups by DNO and computes count & average salary per department.)

17
Q

What is unique about the COUNT function in RA?

A

It does not matter which attribute is counted—it always returns the number of tuples.

18
Q

Does RA remove duplicates before computing SUM, COUNT, or AVERAGE?

A

No, duplicates remain during calculation.

19
Q

Why is Relational Algebra Important?
Why is Relational Algebra fundamental to databases?

A

It forms the foundation of SQL queries.
Helps in query optimization.
Provides a formal way to express data retrieval.

20
Q

What are the most important takeaways from Relational Algebra?

A

✔ Selection (𝞂), Projection (π), Renaming (ρ).
✔ Joins & Foreign Keys.
✔ Set Operations (∪, ∩, -).
✔ Aggregation & Grouping.
✔ Outer Joins for handling missing data.