1
Introduction to Data Management CSE 344
Section 6: Relational Calculus and Some XML
CSE 344 - Fall 2015
Introduction to Data Management CSE 344 Section 6: Relational - - PowerPoint PPT Presentation
Introduction to Data Management CSE 344 Section 6: Relational Calculus and Some XML CSE 344 - Fall 2015 1 Relational Calculus Review Relational predicate P is a formula given by this grammar: P ::= atom | P P | P P | P P | not(P)
1
CSE 344 - Fall 2015
P ::= atom | P ∧ P | P ∨ P | P⇒P | not(P) | ∀x.P | ∃x.P
Q(x1, …, xk) = P
CSE 344 - Fall 2015 2
Find drinkers that frequent some bar that serves some beer they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
CSE 344 - Fall 2015 3
Find drinkers that frequent some bar that serves some beer they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
CSE 344 - Fall 2015 4
Find drinkers that frequent some bar that serves some beer they like. Find drinkers that frequent only bars that serves some beer they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
CSE 344 - Fall 2015 5
Find drinkers that frequent some bar that serves some beer they like. Find drinkers that frequent only bars that serves some beer they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
CSE 344 - Fall 2015 6
Find drinkers that frequent some bar that serves some beer they like. Find drinkers that frequent only bars that serves some beer they like. Find drinkers that frequent some bar that serves only beers they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
CSE 344 - Fall 2015 7
Find drinkers that frequent some bar that serves some beer they like. Find drinkers that frequent only bars that serves some beer they like. Find drinkers that frequent some bar that serves only beers they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
CSE 344 - Fall 2015 8
Find drinkers that frequent some bar that serves some beer they like. Find drinkers that frequent only bars that serves some beer they like. Find drinkers that frequent only bars that serves only beer they like. Find drinkers that frequent some bar that serves only beers they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
CSE 344 - Fall 2015 9
Find drinkers that frequent some bar that serves some beer they like. Find drinkers that frequent only bars that serves some beer they like. Find drinkers that frequent only bars that serves only beer they like. Find drinkers that frequent some bar that serves only beers they like.
Likes(drinker, beer) Frequents(drinker, bar) Serves(bar, beer)
10 CSE 344 - Fall 2015
CSE 344 - Fall 2015 11
Uses(recipe, ingredient_name) Ingredient(name, category)
We have a database of recipes and ingredients. An ingredient has a name and a category (meat, dairy, veggie, etc.). The relation uses captures which recipe uses which ingredient. Write a relational calculus query that returns all recipes that use ingredients from at least two different categories.
CSE 344 - Fall 2015 12
We have a database of recipes and ingredients. An ingredient has a name and a category (meat, dairy, veggie, etc.). The relation uses captures which recipe uses which ingredient. Write a relational calculus query that returns all recipes that use only
Uses(recipe, ingredient_name) Ingredient(name, category)
CSE 344 - Fall 2015 13
We have a database of recipes and ingredients. An ingredient has a name and a category (meat, dairy, veggie, etc.). The relation uses captures which recipe uses which ingredient. Write a relational calculus query that returns all ingredients that are never used in a recipe.
Uses(recipe, ingredient_name) Ingredient(name, category)
CSE 344 - Fall 2015 14
We have a database of recipes and ingredients. An ingredient has a name and a category (meat, dairy, veggie, etc.). The relation uses captures which recipe uses which ingredient. Write a relational calculus query that returns pairs of recipes that use the same categories of ingredients but never dairy.
Uses(recipe, ingredient_name) Ingredient(name, category)
CSE 344 - Fall 2015 15
<result> { Xpath expression} </result>
$ java -cp saxon9he.jar net.sf.saxon.Query ex.xq > a1.xml
$ xmllint --format a1.xml