Relational Algebra Flashcards
What is one of the central functions of a DBMS (Database management system)?
One of the central functions of a DBMS (Database management system) is to answer questions about the data posed to it by users.
What is Relational Algebra?
It is a specification language that is not meant to be directly implementable. (Like SQL)
For our purposes it is an extension of set theory.
What does Relational Algebra provide?
Relational Algebra provides a theoretical foundation for relational databases and a means to contruct queries.
What is the answer to following problems:
Union:
{1,2,3} ∪ {3,4,5} = ?
Intersection:
{1,2,3} ∩ {3,4,5} = ?
Difference:
{1,2,3} − {3,4,5} = ? (kan vara “/” tror jag)
Cartesiasn product:
{1,2} × {3,4} = ?
Union:
{1,2,3} ∪ {3,4,5} = {1,2,3,4,5}
Intersection:
{1,2,3} ∩ {3,4,5} = {3}
Difference:
{1,2,3} − {3,4,5} = {1,2}
Cartesiasn product:
{1,2} × {3,4} = {(1,3), (1,4), (2,3), (2,4)}
What is Queries in relational algebra based upon?
- Queries in relational algebra are based upon the use of three elementary operations on tables:
- Project
- Restrict
- Rename
- Along with derived operations such as “Joins”.
What is the result of applying an operation in relational algebra? And what does that mean?
- the result of applying an operation is itself a table, that means we can compose operations, much like mathematics.
What does applying the elementaty operation Π “Project” to a table Yield in relational algebra?
Applying “Project” to a table yields a copy of that table, but with some of its
attributes (i.e. columns) excluded.
What does applying the elementaty operation
σ “Restrict” to a table Yield in relational algebra?
Applying Restrict to a table yields a copy of that table, but with
some of its rows (i.e. tuples) excluded.
Why do we allow “temporary” tables to be given names?
As queries get more complicated, requiring the use of two, three, or more
nested applications of Project and/or Restrict, they become difficult to
understand.
Hence, we allow ”temporary” tables to be given names.
How is a Rename expression written as?
A Rename expression is written as:
P a←b(table)
What is the result of the elementary operation “Rename” in relational algebra?
A Rename expression is written as:
P a←b(table)
the result is that the “b” attribute is renamed
to an “a” attribute.
Where does the “Natural-Join” operation become useful? in Relational Algebra.
In any but the most trivial relational databases there will be
two, three or possibly many more tables.
In such a setting, to answer the most interesting queries will
require the use of two or more tables.
Remember we don’t want to just stick two tables together as
we might lose all the nice properties that normalization got us.
Instead, we want to link tables together using a foreign key
referring to a primary key mechanism.
This is where the Natural-Join operation becomes useful.
How is an “Natural-Join” application written? And what is the result of the example?
It is written as:
R ⋈ S
Where R and S are relations.
The result of the natural join is the set of all combinations of tuples
in R and S that are equal on their common attribute names.
How does the Join operation work?
The -Join computes all combinations of tuples from R to S that satisfy a
condition
Student(studNum, name, address, degSubject)
Course(code, title)
Registered(studNum, code)
Sample Exam Question:
1. Write a relational algebra query to list the titles of courses that have students
registered on them.
t1 = Course ⨝ Registered
π title (t1)