3. Formal Relational Query Languages Flashcards

1
Q

What are the two types of Relational Query Languages?

A
  • Relational algebra (procedural), consists of a set of operations that take one or two relations as input and produce a new relation as their result.
  • Relational calculus (declarative), describes the desired information without giving a specific procedure for obtaining that information.
  • Note that they are logically equivalent and can express the same queries (Codd’s theorem)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the basis of a relational algebra query?

A

It explains how to obtain the result

e.g course_id (semester=“Fall” Λ year=2014)

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

What is the basis of a relational calculus query?

A

It explains what is required

e.g {t | t in instructor Λ t[salary]>25000 }

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

What are the 6 fundamental relational algebra operations?

A
  • Select (unary)
  • Project (unary)
  • Rename (unary)
  • Union (binary)
  • Set difference (binary)
  • Cartesian product (binary)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What 2 operations can you derive from the fundamental relational algebra operations?

A
  • Set intersection (binary)

* Natural join (binary)

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

What is Select?

A

Selection of tuples from a relation
• σ p(r)
• p = selection predicate, condition for selection
σ p(r) = {t | t ε r p(t)}

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

What is Project?

A

Selection of attributes from a relation
• π A1, A2, … Ak (r)
• r = relation name
π staff_id, name, salary (instructor)

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

What is Union?

A

Tuples that appear in r or s or both
• r ∪ s
• r ∪ s={t|t ε r Λ t ε s}

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

What 2 conditions have to be valid for Union?

A
  1. r, s must have same arity (same number of attributes)

2. The attribute domains must be compatible

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

What is Set difference?

A

Tuples that appear in r but not in s
• r – s
• Same conditions as Union

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

What is Cartesian product?

A

Combine two relations: each tuple in r is joined with each tuple in s
• r x s
• r x s = {t q | t ε r Λ q ε s}

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

What is Set intersection?

A

Tuples that appear in both r and s
• r ∩ s
• r ∩ s = { t | t ε r Λ t ε s }

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

What is Natural join?

A

Combine two relations by matching values of common attributes in r and s
• r ⨝ s

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