Nessun titolo diapositiva

Download Report

Transcript Nessun titolo diapositiva

Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Chapter 3
Relational
algebra and
calculus
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
1
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Query languages for relational databases
• Operations on databases:
– queries: "read" data from the database
– updates: change the content of the database
• Both can be modeled as functions from databases to databases
• Foundations can be studied with reference to query languages:
– relational algebra, a "procedural" language
– relational calculus, a "declarative" language
– (briefly) Datalog, a more powerful language
• Then, we will study SQL, a practical language (with declarative
and procedural features) for queries and updates
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
2
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Relational algebra
• A collection of operators that
– are defined on relations
– produce relations as results
and therefore can be combined to form complex expressions
• Operators
– union, intersection, difference
– renaming
– selection
– projection
– join (natural join, cartesian product, theta join)
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
3
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Union, intersection, difference
• Relations are sets, so we can apply set operators
• However, we want the results to be relations (that is,
homogeneous sets of tuples)
• Therefore:
– it is meaningful to apply union, intersection, difference only
to pairs of relations defined over the same attributes
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
4
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Union
Graduates
Number
7274
7432
9824
Surname
Robinson
O'Malley
Darkes
Age
37
39
38
Surname
O'Malley
O'Malley
Darkes
Age
56
39
38
Managers
Number
9297
7432
9824
Graduates  Managers
Number
7274
7432
9824
9297
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Surname
Robinson
O'Malley
Darkes
O'Malley
Age
37
39
38
56
5
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Intersection
Graduates
Number
7274
7432
9824
Surname
Robinson
O'Malley
Darkes
Age
37
39
38
Managers
Number
9297
7432
9824
Surname
O'Malley
O'Malley
Darkes
Age
56
39
38
Graduates  Managers
Number
7432
9824
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Surname
O'Malley
Darkes
Age
39
38
6
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Difference
Graduates
Number
7274
7432
9824
Surname
Robinson
O'Malley
Darkes
Age
37
39
38
Number
7274
Managers
Number
9297
7432
9824
Graduates - Managers
Surname
O'Malley
O'Malley
Darkes
Surname
Robinson
Age
37
Age
56
39
38
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
7
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
A meaningful but impossible union
Paternity
Father
Adam
Adam
Abraham
Abraham
Child
Cain
Abel
Isaac
Ishmael
Maternity
Mother
Eve
Eve
Sarah
Hagar
Child
Cain
Seth
Isaac
Ishmael
Paternity  Maternity ???
• the problem: Father and Mother are different names, but both
represent a "Parent"
• the solution: rename attributes
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
8
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Renaming
•
•
•
•
unary operator
"changes attribute names" without changing values
removes the limitations associated with set operators
notation:
– Y X.(r)
• example:
– Parent  Father.(Paternity)
• if there are two or more attributes involved then ordering is
meaningful:
– Location,Pay  Branch,Salary.(Employees)
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
9
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Renaming, example
Parent  Father.(Paternity)
Paternity
Father
Adam
Adam
Abraham
Abraham
Child
Cain
Abel
Isaac
Ishmael
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Father
Adam
Adam
Abraham
Abraham
Child
Cain
Abel
Isaac
Ishmael
10
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Renaming and union
Paternity
Father
Adam
Adam
Abraham
Abraham
Child
Cain
Abel
Isaac
Ishmael
Maternity
Mother
Eve
Eve
Sarah
Hagar
Child
Cain
Seth
Isaac
Ishmael
Parent  Father.(Paternity)  Parent  Mother.(Maternity)
Parent
Adam
Adam
Abraham
Abraham
Eve
Eve
Sarah
Hagar
Child
Cain
Abel
Isaac
Ishmael
Cain
Seth
Isaac
Ishmael
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
11
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Renaming and union, with more attributes
Employees
Surname
Patterson
Trumble
Staff
Branch
Rome
London
Salary
45
53
Surname
Patterson
Trumble
Factory
Rome
London
Wages
45
53
Location,Pay  Branch,Salary (Employees)  Location,Pay  Factory, Wages (Staff)
Surname
Patterson
Trumble
Cooke
Bush
Location
Rome
London
Chicago
Monza
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Pay
45
53
33
32
12
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Selection and projection
• Two unary operators, in a sense orthogonal:
– selection for "horizontal" decompositions
– projection for "vertical" decompositions
A B C
A B C
Selection

A B C
A B
Projection

McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
13
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Selection
• Produce results
– with the same schema as the operand
– with a subset of the tuples (those that satisfy a condition)
• Notation:
– F(r)
• Semantics:
– F(r) = { t | t r and t satisfies F}
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
14
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Selection, example
Employees
Surname
Smith
Black
Verdi
Smith
FirstName
Mary
Lucy
Nico
Mark
Age
25
40
36
40
Salary
2000
3000
4500
3900
 Age<30 Salary>4000 (Employees)
Surname
Smith
Verdi
FirstName
Mary
Nico
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Age
25
36
Salary
2000
4500
15
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Selection, another example
Citizens
Surname
Smith
Black
Verdi
Smith
FirstName
Mary
Lucy
Nico
Mark
PlaceOfBirth
Rome
Rome
Florence
Naples
Residence
Milan
Rome
Florence
Florence
 PlaceOfBirth=Residence (Citizens)
Surname FirstName PlaceOfBirth
Black
Lucy
Rome
Verdi
Nico
Florence
Residence
Rome
Florence
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
16
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Projection
• Produce results
– over a subset of the attributes of the operand
– with values from all its tuples
• Notation (given a relation r(X) and a subset Y of X):
– Y(r)
• Semantics:
– Y(r) = { t[Y] | t  r }
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
17
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Projection, example
Employees
Surname
Smith
Black
Verdi
Smith
FirstName
Mary
Lucy
Mary
Mark
Department
Sales
Sales
Personnel
Personnel
Head
De Rossi
De Rossi
Fox
Fox
Surname, FirstName(Employees)
Surname
Smith
Black
Verdi
Smith
FirstName
Mary
Lucy
Mary
Mark
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
18
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Projection, another example
Employees
Surname
Smith
Black
Verdi
Smith
FirstName
Mary
Lucy
Mary
Mark
Department
Sales
Sales
Personnel
Personnel
Head
De Rossi
De Rossi
Fox
Fox
Department, Head (Employees)
Department
Sales
Personnel
Head
De Rossi
Fox
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
19
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Cardinality of projections
• The result of a projections contains at most as many tuples as
the operand
• It can contain fewer, if several tuples "collapse"
• Y(r) contains as many tuples as r if and only if Y is a superkey
for r;
– this holds also if Y is "by chance" (not defined as a superkey
in the schema, but superkey for the specific instance), see
the example
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
20
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Tuples that collapse
Students
RegNum
284328
296328
587614
934856
965536
Surname
Smith
Smith
Smith
Black
Black
Surname, DegreeProg (Students)
FirstName
Luigi
John
Lucy
Lucy
Lucy
Surname
Smith
Smith
Black
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
BirthDate
29/04/59
29/04/59
01/05/61
01/05/61
05/03/58
DegreeProg
Computing
Computing
Engineering
Fine Art
Fine Art
DegreeProg
Computing
Engineering
Fine Art
21
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Tuples that do not collapse, "by chance"
Students
RegNum
296328
587614
934856
965536
Surname
Smith
Smith
Black
Black
Surname, DegreeProg (Students)
FirstName
John
Lucy
Lucy
Lucy
Surname
Smith
Smith
Black
Black
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
BirthDate
29/04/59
01/05/61
01/05/61
05/03/58
DegreeProg
Computing
Engineering
Fine Art
Engineering
DegreeProg
Computing
Engineering
Fine Art
Engineering
22
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Join
• The most typical operator in relational algebra
• allows to establish connections among data in different
relations, taking into advantage the "value-based" nature of the
relational model
• Two main versions of the join:
– "natural" join: takes attribute names into account
– "theta" join
• They are all denoted by the symbol 
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
23
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
A natural join
r1
Employee
Smith
Black
White
Department
sales
production
production
r1  r2
Employee
Smith
Black
White
r2
Department
production
sales
Department
sales
production
production
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Head
Mori
Brown
Head
Brown
Mori
Mori
24
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Natural join: definition
• r1 (X1), r2 (X2)
• r1  r2 (natural join of r1 and r2) is a relation on X1X2 (the union
of the two sets):
{ t on X1X2 | t [X1]  r1 and t [X2]  r2 }
or, equivalently
{ t on X1X2 | exist t1  r1 and t2  r2 with t [X1] = t1 and t [X2] = t2 }
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
25
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Natural join: comments
• The tuples in the result are obtained by combining tuples in the
operands with equal values on the common attributes
• The common attributes often form a key of one of the operands
(remember: references are realized by means of keys, and we
join in order to follow references)
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
26
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Another natural join
Offences
Cars
Code
143256
987554
987557
630876
539856
Date
Officer Dept
75
25/10/1992 567
75
26/10/1992 456
75
26/10/1992 456
47
15/10/1992 456
47
12/10/1992 567
Registration
6544 XY
7122 HT
5694 FR
6544 XY
Offences  Cars
Code
Date
Officer Dept
75
143256 25/10/1992 567
75
987554 26/10/1992 456
75
987557 26/10/1992 456
47
630876 15/10/1992 456
47
539856 12/10/1992 567
Dept
75
75
75
47
Registartion
5694 FR
5694 FR
6544 XY
6544 XY
6544 XY
Owner
Cordon Edouard
Cordon Edouard
Latour Hortense
Mimault Bernard
Registration
5694 FR
5694 FR
6544 XY
6544 XY
6544 XY
Owner
Latour Hortense
Latour Hortense
Cordon Edouard
Cordon Edouard
Cordon Edouard
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
…
…
…
…
…
…
…
…
…
…
…
27
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Yet another join
• Compare with the union:
– the same data can be combined in various ways
Paternity
Father
Adam
Adam
Abraham
Abraham
Child
Cain
Abel
Isaac
Ishmael
Paternity
Maternity
Mother
Eve
Eve
Sarah
Hagar
Child
Cain
Seth
Isaac
Ishmael
 Maternity
Father
Adam
Abraham
Abraham
Child
Cain
Isaac
Ishmael
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Mother
Eve
Sarah
Hagar
28
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Joins can be "incomplete"
• If a tuple does not have a "counterpart" in the other relation,
then it does not contribute to the join ("dangling" tuple)
r1
Employee
Smith
Black
White
Department
sales
production
production
r1  r2
Employee
Black
White
r2
Department
production
purchasing
Department
production
production
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Head
Mori
Brown
Head
Mori
Mori
29
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Joins can be empty
• As an extreme, we might have that no tuple has a counterpart,
and all tuples are dangling
r1
Employee
Smith
Black
White
Department
sales
production
production
r1  r2
Employee
r2
Department
marketing
purchasing
Department
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Head
Mori
Brown
Head
30
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
The other extreme
• If each tuple of each operand can be combined with all the
tuples of the other, then the join has a cardinality that is the
product of the cardinalities of the operands
r1
Employee
Smith
Black
White
Project
A
A
A
r1  r2
Employee
Smith
Black
White
Smith
Black
White
r2
Project
A
A
A
A
A
A
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Project
A
A
Head
Mori
Brown
Head
Mori
Brown
Mori
Brown
Mori
Brown
31
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
How many tuples in a join?
Given r1 (X1), r2 (X2)
• the join has a cardinality between zero and the products of the
cardilnalities of the operands:
0  | r 1  r 2 |  | r 1 |  | r 2|
(| r | is the cardinality of relation r)
• moreover:
– if the join is complete, then its cardinality is at least the
maximum of | r1 | and | r2|
– if X1X2 contains a key for r2, then | r1  r2 |  | r1|
– if X1X2 is the primary key for r2, and there is a referential
constraint between X1X2 in r1 and such a key, then
| r 1  r 2 | = | r 1|
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
32
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Outer joins
• A variant of the join, to keep all pieces of information from the
operands
• It "pads with nulls" the tuples that have no counterpart
• Three variants:
– "left": only tuples of the first operand are padded
– "right": only tuples of the second operand are padded
– "full": tuples of both operands are padded
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
33
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Outer joins
r1
Employee
Smith
Black
White
Department
sales
production
production
r1  LEFTr2
r1
 RIGHT
r2
 FULL r2
Department
production
purchasing
Employee
Smith
Black
White
Department
Sales
production
production
Head
Employee
Black
White
Department
production
production
purchasing
Head
Mori
Mori
Brown
Department
Sales
production
production
purchasing
Head
NULL
r1
r2
Employee
Smith
Black
White
NULL
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Head
Mori
Brown
NULL
Mori
Mori
NULL
Mori
Mori
Brown
34
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
N-ary join
• The natural join is
– commutative: r1  r2 = r2  r1
– associative: (r1  r2)  r3 = r1  (r2  r3)
• Therefore, we can write n-ary joins without ambiguity:
r1  r2  …  rn
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
35
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
N-ary join
r1
Employee
Smith
Black
Brown
White
Department
sales
production
marketing
production
r3
r1  r2  r3
Employee
Black
Brown
White
r2
Division
A
B
Department
production
marketing
production
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Department
production
marketing
purchasing
Division
A
B
B
Head
Mori
Brown
Division
A
B
A
Head
Mori
Brown
Mori
36
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Cartesian product
• The natural join is defined also when the operands have no
attributes in common
• in this case no condition is imposed on tuples, and therefore the
result contains tuples obtained by combining the tuples of the
operands in all possible ways
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
37
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Cartesian product: example
Employees
Employee
Smith
Black
Black
Project
A
A
B
Projects
Code
A
B
Name
Venus
Mars
Employes  Projects
Employee
Smith
Black
Black
Smith
Black
Black
Project
A
A
B
A
A
B
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Code
A
A
A
B
B
B
Name
Venus
Venus
Venus
Mars
Mars
Mars
38
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Theta-join
• In most cases, a cartesian product is meaningful only if followed
by a selection:
– theta-join: a derived operator
r1 F r2 = F(r1  r2)
– if F is a conjunction of equalities, then we have an equi-join
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
39
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Equi-join: example
Employees
Employee
Smith
Black
Black
Project
A
A
B
Projects
Code
A
B
Name
Venus
Mars
Employes Project=Code Projects
Employee
Smith
Black
Black
Project
A
A
B
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Code
A
A
B
Name
Venus
Venus
Mars
40
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Queries
• A query is a function from database instances to relations
• Queries are formulated in relational algebra by means of
expressions over relations
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
41
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
A database for the examples
Employees
Number
101
103
104
105
210
231
252
301
375
Name
Mary Smith
Mary Bianchi
Luigi Neri
Nico Bini
Marco Celli
Siro Bisi
Nico Bini
Steve Smith
Mary Smith
Age
34
23
38
44
49
50
44
34
50
Salary
40
35
61
38
60
60
70
70
65
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Supervision
Head
210
210
210
231
301
301
375
Employee
101
103
104
105
210
231
252
42
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Example 1
• Find the numbers, names and ages of employees earning more
than 40 thousand.
Number
104
210
231
252
301
375
Name
Luigi Neri
Marco Celli
Siro Bisi
Nico Bini
Steve Smith
Mary Smith
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
Age
38
49
50
44
34
50
43
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Example 2
• Find the registration numbers of the supervisors of the
employees earning more than 40 thousand
Head
210
301
375
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
44
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Example 3
• Find the names and salaries of the supervisors of the
employees earning more than 40 thousand
NameH
Marco Celli
Steve Smith
Mary Smith
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
SalaryH
60
70
65
45
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Example 4
• Find the employees earning more than their respective
supervisors, showing registration numbers, names and salaries
of the employees and supervisors
Number
104
252
Name
Luigi Neri
Nico Bini
Salary
61
70
NumberH
210
375
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
NameH
Marco Celli
Mary Smith
SalaryH
60
65
46
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Example 5
• Find the registration numbers and names of the supervisors
whose employees all earn more than 40 thousand
Number
301
375
Name
Steve Smith
Mary Smith
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
47
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Algebra with null values
People
Name
Aldo
Andrea
Maria
Age
35
27
NULL
Salary
15
21
42
•  Age>30 (People)
• which tuples belong to the result?
• The first yes, the second no, but the third?
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
48
Database Systems (Atzeni, Ceri, Paraboschi, Torlone)
Chapter 3 : Relational algebra and calculus
Material on relational calculus and Datalog will be provided in the
near future.
Please contact Paolo Atzeni ([email protected])
for more information
McGraw-Hill and Atzeni, Ceri, Paraboschi, Torlone 1999
49