Relational algebra Flashcards
Name 2 unary operations in relational algebra
- Projection
- Selection
Explain the unary operation projection
Symbol: pi
Operation: selects attributes removing duplicate tuples
Example: pi attribute1, attribute2, … attributeN (tableName)
SQL equivalent: SELECT attribute1, attribute2, …, attributeN FROM (tableName)
Explain unary operation selection
Symbol: σ
Operation: Selects tuples by predicate
Example: σ predicate (TableName)
SQL equivalent: WHERE predicate (FROM tableName)
Name and describe the 5 binary operations in relational algebra
Cartesian product
Union
Intersection
Difference
Join
Explain the binary operation cartestian product
Symbol: x
Operation: Shows a concatenation of all tuples in two relations
Example: A x B
SQL equivalent: CROSS join
Explain the binary operation union
Symbol: U
Operation: Gets all the tuples in either one or both relations
Example: Relation U Relation
SQL equivalent: UNION
Explain the binary operation intersection
Symbol: ⋂
Operation: Gets all the tuples present in BOTH relations
Example: Relation ⋂ Relation
SQL equivalent: INTERSECT
Explain the binary operation difference
Symbol: -
Operation: Gets all the tuples in one set but NOT in another
Example: Relation - Relation
SQL equivalent: EXCEPT/MINUS
Explain the binary operation join?
Symbol: ⋈
Operation: Joins two relations over all common attributes x
Example: Relation ⋈ Relation
SQL equivalent: INNER JOIN
What does it mean if two sets are union compatible?
- There is the same number of attributes
- Attributes have the same domain
What is the set equivalence to A ⋂ B?
A - (A - B)
What is the difference between relational algebra and SQL?
Relational algebra is the formal language
- Theoretical foundations of SQL
SQL is the ‘real language’
- Actually use it in databases
What are the fundamental relational algebra operations?
Selection
Projection
Cartesian product
Union
Set difference
What are NOT the fundamental relational algebra operations?
Join
Intersection
What makes an operation fundamental?
If it cannot be made up of anything other than itself