Relational Algebra Flashcards
What does the projection operation do, and what is the notation?
It returns a relation that only includes the attributes given in the projection.
E.G. π{l, k}R will project out the columns l and k from relation R.
Like a select query in SQL.
Write the notation to project CourseNo and Title from the following table, and calculate the result:
Course
CourseNo title year c1 aa 3 c2 bb 2 c3 cc 1
π{CourseNo, Title}Course
CourseNo Title c1 aa c2 bb c3 cc
What is the Cartesian Product operation, and how is it written?
Returns all combinations of rows from the two supplied relations
RelationA ⊗ RelationB
What do you do if R1 and R2 have a column of the same name, and you want to calculate the cartesian product?
In the result rename the conflicting columns to R1.Name and R2.Name
If you are cartesianing the same table, it becomes R1.Name and R1′.Name
What is the selection operation and how is it written?
Selects rows from a relation if they meet the predicate.
Notation:
σP(R)
i.e. select all rows from R according to predicate P
Example:
σTitle=bb(Course)
How do you combine projection and selection?
π{Attribute}σPredicate(Relation)
What is natural join, and how is it written?
Combines all the attributes in R and S for each row identified by a common attribute a
i.e. if a is the same in both relations, the row is made
example:
R⋈S = π{all attributes}σR.a=S.a(R⊗S)
How is Union handled in relational algebra?
Relations are considered to be sets of tuples
Must be of the same type
Input types: two set([l:A,k:b])
Output type: one set([l:A,k:b])
Any members in R1 or R2 will be in R1 U R2