Lecture 7 Flashcards

1
Q

What are some of the limitations of relational algebra?

A

No aggregation operators (e.g. average, minimum, …), no duplicates allowed (which is problematic when counts matter, and could be expensive to compute)

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

What are the difference, and similarity between a bag, and a set?

A

Both say nothing about the order. Bags can have repetition.

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

Can you calculate the number of times a value appears in a bag for the intersection, union and difference? Assume that tuple t appears n times in R and m times in S.

A

R (union) S has n + m copies of t, R (intersection) S has min(n, m) copies of t, R - S has max(0, n - m) copies of t

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

What additional operations does SQL implement in addition to pure relational algebra?

A

delta: duplicate-elimination operator, gamma: grouping operator (i.e. group by attribute, then find aggregate within group), aggregation operator: (e.g. SUM), pi: extended projection operator to transom attributes, tau: sorting operator, outerjoin operator: join where unmatched tuples are kept.

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

How do aggregation operators deal with NULL?

A

Usually it’s ignored, however when counting the entire table it’s not.

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

What types of transformations can be done with the extended projection?

A

Type 1: Select attribute of R,
Type 2: Rename expression OR,
Type 3: create expression that requires evaluation.

Type 3 can have scalars and/or numerical attributes of R, to which we can apply e.g. addition, subtraction, division,… or it can have strings(-like) attributes of R e.g. for concatenation

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

How does an outer join work with tuples that cannot be matched?

A

They are kept, ad padded by null values for absent attributes in join.

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

What are the variations of the outer join?

A

Full outerjoin, left outer join (only keep dangling tuples from the left), right outer join. (both for natural and theta-join).

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

How does a basic SELECT query (with WHERE) statement work?

A

SELECT L FROM R WHERE C;

Here L is a list of tuples you want from the relation, R the table, C a certain condition.

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

Whare are some of the attributes that can be used for a SELECT statement?

A

+ for addition, - for subtraction (and changing sign), * for multiplication, / for division, DIV for integer division, % for modulo.

Many implementations also offer a lot more

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

How can you compare strings in SQL with the LIKE statement?

A

You can just compare to strings, however you can also create a pattern where (low underscore) can be one of any character, and % is can be any number of any characters.

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

Why is an escape character used, and how can you define it?

A

The % has as another meaning that it is a joker for any number of characters, however if we want to find % itself we need to define an escape as follows: e.g. LIKE ‘x%’ ESCAPE ‘x’.

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

How to test if NULL in SQL?

A

We can test using X IS NULL, and X IS NOT NULL.

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

How do the AND, OR, and XOR, operators deal with NULL?

A

AND: NULL when with TRUE, FALSE when with FALSE,
OR: NULL when with FALSE, TRUE when with TRUE,
XOR: NULL when one is NULL.

If both are NULL, all return NULL

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

How to order in SQL?

A

Just add at the end ORDER BY and then a list of items you want to order by. 1st has highest priority, etc.

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