Relational Algebra Flashcards

1
Q

What is one of the central functions of a DBMS (Database management system)?

A

One of the central functions of a DBMS (Database management system) is to answer questions about the data posed to it by users.

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

What is Relational Algebra?

A

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.

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

What does Relational Algebra provide?

A

Relational Algebra provides a theoretical foundation for relational databases and a means to contruct queries.

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

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} = ?

A

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)}

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

What is Queries in relational algebra based upon?

A
  • 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”.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the result of applying an operation in relational algebra? And what does that mean?

A
  • the result of applying an operation is itself a table, that means we can compose operations, much like mathematics.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does applying the elementaty operation Π “Project” to a table Yield in relational algebra?

A

Applying “Project” to a table yields a copy of that table, but with some of its
attributes (i.e. columns) excluded.

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

What does applying the elementaty operation

σ “Restrict” to a table Yield in relational algebra?

A

Applying Restrict to a table yields a copy of that table, but with
some of its rows (i.e. tuples) excluded.

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

Why do we allow “temporary” tables to be given names?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is a Rename expression written as?

A

A Rename expression is written as:

P a←b(table)

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

What is the result of the elementary operation “Rename” in relational algebra?

A

A Rename expression is written as:

P a←b(table)

the result is that the “b” attribute is renamed
to an “a” attribute.

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

Where does the “Natural-Join” operation become useful? in Relational Algebra.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is an “Natural-Join” application written? And what is the result of the example?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does the Join operation work?

A

The -Join computes all combinations of tuples from R to S that satisfy a
condition

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

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.

A

t1 = Course ⨝ Registered

π title (t1)

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

Student(studNum, name, address, degSubject)

Course(code, title)

Registered(studNum, code)

Sample Exam Question:
2. Write a relational algebra query to list the names of students and the titles of
courses that they are registered for.

A

t1 = Course ⨝ Registered
t2 = Student ⨝ t1
π name, title (t2)

17
Q

Student(studNum, name, address, degSubject)

Course(code, title)

Registered(studNum, code)

Sample Exam Question:
3. Write a relational algebra query to list the StudNum of students who are
registered either for the Database course of for the Algorithms course.

A

t1 = Course ⨝ Registered
t2 = σ title = ‘Algorithms’ ∨ ‘Databases’(t1)
π studNum (t2)

18
Q

What are the boolean conditions in Relational Algebra?

A

The boolean conditions AND (^), OR (V) and NOT(!=)

By using operators such as AND (^), OR (V) and NOT(!=) in the
condition, means we can express more complicated queries.

(!=