RELATIONAL ALGEBRA Flashcards
Define relational algebra
Relational algebra is a procedural query language which tasks instances of relations as input and yields instances of relations as output
Define relational calculus
Relational Calculus is a non-procedural query language ie it tells what to do but never explains how to do it
What are the differences between relational algebra and relational calculus?
- Relaional algebra is a procedural language while RC is a declarative language
- RA states how to obtain the result while RC states what result we have to obtain
- RA describes the order in which operations have to be performed while RC does not specify the order of operations
- RA is not domain dependent (data types allowed- domain) while relational Calculus ca be domain dependent
- RA is close to a programming language while RC is closer to natural language
Explain the projection operation And give its syntax
Returns columns from relation.
π (name-of-column) name-or relation
*Check Liban’s notes for syntax
Explain the select operation And give its syntax
Selects a subset of rows from relation.
*Check Liban’s notes for syntax
Explain the union relation And give its syntax
Tuples in reln. 1 and in reln. 2.
*Check Liban’s notes for syntax
Explain set difference And give its syntax
Tuples in reln. 1, but not in reln. 2.
*Check Liban’s notes for syntax
Explain Cartesian product And give its syntax
Allows us to combine two relations.
*Check Liban’s notes for syntax
What is union compatibility?
Same number of fields.
‘Corresponding’ fields have the same data type.
*This condition is necessary for union, set difference and intersection operations
Explain the rename operation And give its syntax
If renaming table don’t put it in brackets if renaming columns place them in brackets Eg
ρ pro(A,B) (Project) -Query to rename the table name Project to Pro and its attributes to A B
*Check Liban’s notes for syntax
Describe what a join is and give its different types
Can be defined as cross-product followed by selection and projection. • We have several variants of join. ✓ Condition joins ✓ Equijoin ✓ Natural join
Describe the theta/ condition join And give its syntax
combines two relations based on specified condition(s)
*see Liban’s notes for syntax
Describe the equijoin And give its syntax
A special case of condition join where the condition c
contains only equalities.
*Result schema similar to cross-product, but only one copy of fields for which equality is specified. *Check notes for syntax
Describe the natural join And give its syntax
Equijoin on all common fields
*Check Liban’s notes for syntax