Logic to SQL Expressions - Using Logic to Create SQL What...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Using Logic to Create SQL
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What Are We Trying To Do Create Logical Expressions (or Relational Calculus Expressions) to define what Queries or Constraints we want to express Using the fact that Relational Databases are Set Oriented Transform them into SQL Equivalents
Background image of page 2
Transformation Rules Equivalences exp1 'is equivalent to' exp2 - Generally the '3 bar' ≡ sign Identities If exp1 and exp2 are “identically equal” then they have identical semantics Rewrite Rules An expression containing an occurrence of exp1 can be rewritten as an expression containing an occurrence of exp2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Some Laws Implication Law If p then q ≡ (not p) or q Double Negation Law not (not p) ≡ p DeMorgan's Law not (p and q) ≡ (not p) or (not q) not (p or q) ≡ (not p) and (not q) Put them all together If p then q ≡ not (p and not q)
Background image of page 4
Some More Laws Distributive Law p and (q or r) ≡ (p and q) or (p and r) p or (q and r) ≡ (p or q) and (p or r) Quantification Law Just and application of DeMorgan's Law to Quantification Forall x (p(x) ≡ not (Exists x (not p(x))) Exists x (p(x) ≡ not (Forall x (not p(x))) not (Exists x (p(x)) ≡ Forall x (not p(x)) not (Forall x (p(x)) ≡ Exists x (not p(x))
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Logical Implication If color = 'red' then city = 'London' (not (color = 'red')) or city = 'London' Constraint c1 check((not color = 'red') or city = 'London'); Constraint c1 check(color <> 'red or city = 'London');
Background image of page 6
Universal Quantification Forall px (if px.color = 'red' then px.city = 'London') SQL does not do Forall not (exists px (not (if px.color = 'red' then px.city = 'London'))) not (exists px (not (not ((px.color = 'red') and not
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 28

Logic to SQL Expressions - Using Logic to Create SQL What...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online