Week 3 - Relational Algebra Flashcards

1
Q

What can RA be thought of as?

A

An intermediary language between SQL and maths/semantics.

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

Principle relation operation: Select

A

Pick rows from a relation by some condition

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

Principle relation operation: Project

A

Pick columns by name

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

Principle relation operation: Join

A

Connect two relations usually by a Foreign Key

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

Set operation: Union

A

Make the table containing all the rows of two relations, removing duplicates. The two relations must be union compatible (i.e. have the same number of attributes drawn from the same domain, but maybe having different names)

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

Set operation: Intersection

A

Pick the rows which are common to two relations

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

Set operation: Difference

A

Pick the rows which are in one table but not another

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

Set operation: Cartesian Product

A

Pair off each of the tuples in one relation with those in another - creating a double sized row for each pair.

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

DEPARTMENT (Dnum, Dname, Manager)

How do you indicate that an attribute is a primary/foreign key?

A

Underlining it means it is a primary key.

Italicizing it means it is a foreign key.

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

Translate the SQL into RA:

SELECT * FROM employee WHERE CITY=‘London’

A

LOCALS := σ(EMPLOYEE, CITY = “LONDON”)

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

Translate the RA into SQL:

LONDONorYOUNGRICH :=σ(EMPLOYEE,
CITY=“LONDON” or(SALARY>100KandAGE<30))

A

SELECT * FROM employee WHERE CITY=‘LONDON’ OR (SALARY > 100000 AND AGE < 30]

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

Translate the RA into SQL:

Π(EMPLOYEE, (SEX, SALARY))

A

SELECT SEX, SALARY FROM EMPLOYEE

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

Explain what this RA does:

Π(σ(EMPLOYEE, CITY = “LONDON”), (NAME,NI))

A

It performs a selection, returning the rows in the employee table where the city attribute holds the value ‘LONDON’. After that, it performs a projection using those rows, where it returns the NAME and NI columns of those rows.

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

Give an example of a join in RA

A

⨂(EMPLOYEE, Dept, DEPARTMENT, DNum)

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

Give an example of a union operation in RA

A

LondonOrRich := σ(EMPLOYEE, CITY = “LONDON”) U σ(EMPLOYEE, SALARY > 100K)

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

Give an example of an intersection operation in RA

A

FemalesInLondon := σ(EMPLOYEE, CITY = “LONDON) ∩ σ(EMPLOYEE, SEX = “F”)

17
Q

Does intersection exist in MySQL / Oracle?

A

Only in Oracle (INTERSECTION).

18
Q

Give an example of a difference operation in RA

A

NonLocals := EMPLOYEE − LOCALS

19
Q

Does difference exist in MySQL / Oracle?

A

Only in Oracle (MINUS)

20
Q

Give an example of the cartesian product in RA

A

EMPLOYEE × DEPARTMENT

21
Q

Give an example of divison

A

I don’t understand. Need to learn this

22
Q
A