Relational algebra - Theoretical Flashcards

Learn the five fundamental database operations and how they work

1
Q

What is relational algebra?

A

It is a formal language that created to formally describe relational databases

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

What is a relation?

A

A table

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

What is a closure in relational algebra?

A

It is a nested query (subquery) which output is used in the outer query.

e.g:
SELECT * FROM
Employees 
WHERE DName = (SELECT 
Dname 
From Departments
WHERE Dname = "Research")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many operations are there in relational algebra?

A

Originally it included 8 but more have been added since..

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

What is a unary operation?

A

An operation that only involves one single relation (1 table)

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

How many fundamental operations are there in relational algebra?

A

Five;

  1. selection
  2. projection
  3. Cartesian product
  4. union
  5. minus.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the additional operations besides the fundamental ones in relational algebra??

A

Join
intersection
Division operations

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

What is a binary operation?

A

an operation that do work on two relations (2 tables) and results in a single table (it shows the result in a new table).

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

What is the selection operation?

A

Unary operation (works on a single table), it defines a new relation (table) with all the tuples (rows) that is selected (satisfy condition)

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

What is the projection operation?

A

Unary operation that outputs a new relation that contains all the columns of given attributes.

e.g. all names that exist in the table, by selecting all names and phonenumbers.

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

What is the union operation?

A
Binary operation(two relations)
Outputs one relation that contains all the tuples of the two relations without duplications
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the requirements of the union operation?

A

The schemas must match; same number of attributes and the corresponding attributes has the same domain (but naming is irrelevant)

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

What is the minus operation?

A

Binary operation that defines a relation consisting of tuples that are in one but not the other.. So rows that only exist in one of the tables
opposite of intersection

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

What is the intersection operation?

A

binary operation that results in a relation that consist of only the tuples that exist in both realtions.

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

Rename operation

A

unary operation that gives new names to a relation or attributes.

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

Cartesian product operation

A

binary operation that defines a relation, that consists of the concatenation of every tuple of both relations. null can appear

17
Q

What are joins

A

binary operations that outputs one table with data from both tables.

18
Q

What types of joins exist?

A

We distinguish between Inner- and outer-joins.

Inner Joins: Theta, Natural, EQUI
Outer Join: Left, Right, Full

19
Q

What is considered as the default join operation?

A

EQUI / INNER JOIN

20
Q

What is an EQUI / INNER JOIN

A

INNER JOIN that is comparator-based; it uses ‘=’ comparisons to do joins.

21
Q

Here is an example of an equi-join:

A
SELECT *
FROM TableName1, TableName2
WHERE TableName1.ColumnName = TableName2.ColumnName;
-- OR
SELECT *
FROM TableName1
JOIN TableName2
ON TableName1.ColumnName = TableName2.ColumnName;
22
Q

If we do joins with another operator than ‘=’ is it then an equi-join?

A

No, that is a theta join.

a theta join becomes an equi join by using only the = operator

23
Q

What is a theta join

A

It is also an INNER JOIN that allows you to join based on other operators than = like: , ≥, ≠

24
Q

How can you choose between using theta or equi join?

A

If your theta join only uses = DBMS will make use of equi join

25
Q

What is a natural join

A

natural joins are inner joins. They do not use operators. Therefore the attributes need same name and domain and there should be at least one common attribute.

It selects on the common attributes and eliminates duplicate attributes (e.g. if id appears in both)

26
Q

What is the difference between outer and inner joins?

A

an outer join does not require each tuple to have a matching column, whereas the inner joins work by joining on the common column.

27
Q

What are the types of the outer joins?

A

left outer join
right outer join
full outer join

28
Q

What is a left outer join?

A
returns all the rows from the table A even though no match has been found in second table B and still appends the matching rows together, leaving null values where it needs. example of a result:
Num Square Cube
2	      4	      8
3	      9 	      18
4	      16       -
29
Q

what is a right outer join?

A

RIGHT JOIN returns all the columns from the table on the right even if no matching rows have been found in the table on the left.

Where no matches have been found in the table on the left, NULL is returned.

30
Q

What is a full join?

A

It is an outer join that retains all information on both tables.

31
Q

If you want to retain all information from a table while joining another table onto which join should you make?

A

a left or right outer join

32
Q

Can the operations in relational algebra perform mathematical calculations?

A

No for that you need aggregate functions.

Which is, sum() and so on

33
Q

What is aggregate functions?

A

That is functions that you run over attributes of a relation

34
Q

Which aggregate functions are there?

A

COUNT to return the number of values of a given attribute
– SUM to calculate the sum of the values in a given attribute
– AVG to calculate the average value of a given attribute.
– MIN to return the smallest value in a given attribute.
– MAX to return the largest value in a given attribute