Lecture 11 - Relational Algebra Flashcards

1
Q

Query

A
  • A query in relational algebra is an expression composed of various operators that extract or manipulate data from one or more relations.
  • The result of a query is always a relation: a query (expression) on a set of relations produces a relation as a result
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Simplest Query

A

The simplest query is a retrieval of all data from a single relation (table) without any filtering or transformation. It’s equivalent to a SELECT *operation in SQL.

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

Select Operator (σ)

A
  • The Select operator (σ) is used to filter rows in a relation based on a given condition.
    Example:
  • (σGPA > 3.7(Student) selects all students with a GPA greater than 3.7.
  • SQL Equivalent:
    SELECT * FROM Student WHERE GPA > 3.7;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Project Operator (π)

A
  • The Project operator (π) selects specific columns from a relation, effectively reducing the number of attributes.
  • Example: (πname, GPA(Student)) projects the Name and GPA columns from the Student relation.
  • SQL Equivalent:
    • SELECT Name, GPA FROM Student;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Duplicates

A

Relational Algebra inherently operates on sets, which do not allow duplicates. The output of relational algebra operations is a set, meaning it is automatically duplicate-free.

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

Cross Product (x)

A
  • The Cross Product (×) combines every row of one relation with every row of another. It’s also known as the Cartesian product.
  • Example: (Student x Course) pairs each student with every course.
  • SQL Equivalent:
    • SELECT * FROM Student, Course; (without a WHERE clause).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Natural Join (⨝)

A
  • The Natural Join () combines two relations by matching rows based on common attributes (columns with the same name).
  • Example: (Student ⨝ Apply) joins Student and Apply where the common attributes (e.g., Student.ID and Apply.ID) match.
  • SQL Equivalent:
    • SELECT * FROM Student
    • NATURAL JOIN Apply;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Union Operator (∪)

A
  • The Union operator () combines the results of two relations, returning all distinct tuples (rows) present in either relation.
  • Example: (R ∪ S) returns all unique rows from relations R and S.
  • SQL Equivalent:
    • SELECT * FROM R
    • UNION
    • SELECT * FROM S;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Difference Operator (-)

A
  • The Difference operator () returns all tuples that are in one relation but not in the other.
  • Example: (R - S) returns rows in R that are not in S.
  • SQL Equivalent:
    • SELECT * FROM R
    • EXCEPT
    • SELECT * FROM S;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Intersection Operator (∩)

A
  • The Intersection operator () returns only the tuples that are present in both relations.
  • Example: (R ∩ S) returns rows common to both R and S.
  • SQL Equivalent:
    • SELECT * FROM R
    • INTERSECT
    • SELECT * FROM S;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Rename Operator (ρ)

A
  • The Rename operator (ρ) changes the name of a relation or its attributes.
  • Example: (ρs(name)(Student)) renames the Student relation to S and its Name attribute to StudentName.
  • SQL Equivalent:
    • SELECT Name AS StudentName FROM Student;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly