Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Domain Relational Calculus [205]

tuple variable domain variables

 r(a1,a2,...an) where a's are variables or constants


 x y where x,y are variables or constants
 (formula)
 formula

 where A is single attribute

Domain Relational Calculus: Example [206]

Query

Get the names of all all frog muppets.

QBE

muppets NAME ANIMAL COLOR


P. frog

Domain

{ ' }
Query

Get shows casting green muppets.

QBE

muppets NAME ANIMAL COLOR


_kermit green
casting NAME SHOW NETWORK
_kermit P.

Domain

' }

Domain Relational Calculus: Divide [207]

certified
PILOT EQUIPMENT
joe 707
joe 727
joe 747
moe 707
doe 707
doe 727
doe 747
doe 1011

equip
EQUIPMENT
707
727
747

PILOT
joe
doe

certified equip says the pilot is certified on ALL equipment

Tuple Relational Calculus: Divide [208]

Query

Get muppets acting in ALL shows on ABC.

Algebra
Tuple

'

'

Tuple Relational Calculus: Minus [209]

Query

Get muppets acting ONLY on shows on ABC.

Algebra

Tuple

')}
Domain

'))}

Tuple Relational Calculus: Minus [210]

Query

Get the highest rank (join with different names).

Algebra

QBE

RATINGS NETWORK RANK


P. _x

_x

SQL
SELECT r.rank FROM ratings r WHERE r.rank NOT IN
SELECT r1.rank FROM ratings r1,ratings r2

WHERE r1.rank r2.rank

Tuple

Tuple

Domain Relational Calculus: Negate [211]

Query

Get muppets acting ONLY on networks not casting Kermit.

Domain

' }
QBE

CASTING NAME NET


_m _n
`Kermit' _n

TEMP NAME
I. _m
TEMP NAME
_m

CASTING NAME NET


_m

RESULT NAME
I. _m

SQL

SELECT c.name FROM casting c WHERE c.name NOT IN


SELECT d.name FROM casting d, casting e
WHERE d.net = e.net and e.name = `Kermit'

Relational Calculus: Examples [212]

Schema

frequents(DRINKER,BAR) serves(BAR,BEER)
likes(DRINKER,BEER)

Query

Get all drinkers who frequent at least one bar that serves a beer they like.
Algebra

Tuple

Domain

Relational Calculus: Examples [213]

Query

Get the drinkers that frequent no bar that serves a beer they like.

Algebra
Domain

SQL

SELECT f.drinker FROM frequents f


WHERE f.drinker NOT IN
SELECT g.drinker FROM frequents g, serves s, likes l
WHERE g.drinker = l.drinker and s.beer = l.beer and
s.bar = g.bar

Relational Calculus: Examples [214]

Query

Get the drinkers that frequent only bars that serve some beer they like.

Domain

}
Algebra

Algebra

You might also like