370
Relations, Functions, and Matrices
example 23
The operation
restrict PetOwner where PetType = “Dog” giving DogOwner
results in the relation DogOwner.
Dogowner
Name
petName
petType
Breed
Smith, Bob
Spot
Dog
Hound
Jones, Kate Lad
Dog
Collie
Jones, Kate Lassie
Dog
Collie
The operation
project PetOwner over (Name, PetType) giving Preference
results in the relation Preference.
preference
Name
petType
Smith, Bob
Dog
Smith, Mary
Cat
Jones, Kate
Dog
NULL
Fish
Collier, Jon
Bird
White, Janet
Cat
PRaCtiCe 21 Write the relation that results from the operation
project Person over (Name, State) giving Locale
■
Because relations are sets of n-tuples, the binary operations of union, intersection, and set difference can be applied to two relations with the same basic
structure. Thus in our example, two different tables containing information about
pet owners, both laid out with the same structure, could be intersected to produce
a relation containing all the common 4-tuples.
Another binary operation, join, can be performed on two relations with a
common attribute (column). Theoretically, this operation initially forms the Cartesian product of all n-tuples (rows) in the first relation with all k-tuples (rows) in
the second relation. It views the result as a set of (n + k)-tuples and then restricts
to the subset of those where the common attribute has the same value, writing the
Relations, Functions, and Matrices
example 23
The operation
restrict PetOwner where PetType = “Dog” giving DogOwner
results in the relation DogOwner.
Dogowner
Name
petName
petType
Breed
Smith, Bob
Spot
Dog
Hound
Jones, Kate Lad
Dog
Collie
Jones, Kate Lassie
Dog
Collie
The operation
project PetOwner over (Name, PetType) giving Preference
results in the relation Preference.
preference
Name
petType
Smith, Bob
Dog
Smith, Mary
Cat
Jones, Kate
Dog
NULL
Fish
Collier, Jon
Bird
White, Janet
Cat
PRaCtiCe 21 Write the relation that results from the operation
project Person over (Name, State) giving Locale
■
Because relations are sets of n-tuples, the binary operations of union, intersection, and set difference can be applied to two relations with the same basic
structure. Thus in our example, two different tables containing information about
pet owners, both laid out with the same structure, could be intersected to produce
a relation containing all the common 4-tuples.
Another binary operation, join, can be performed on two relations with a
common attribute (column). Theoretically, this operation initially forms the Cartesian product of all n-tuples (rows) in the first relation with all k-tuples (rows) in
the second relation. It views the result as a set of (n + k)-tuples and then restricts
to the subset of those where the common attribute has the same value, writing the
