Logic to SQL Expressions

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

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

Using Logic to Create SQL

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

View Full Document
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
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

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

View Full Document
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)
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))

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

View Full Document
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');
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online