Docsity

Relational Databases-Lecture 12 Slides-Computer Science, Slides of Relational Database Management Systems (RDBMS)

Partial preview of the text

Download Relational Databases-Lecture 12 Slides-Computer Science and more Slides Relational Database Management Systems (RDBMS) in PDF only on Docsity!

Relational Databases - Comp2400 / Comp

Lecture 16: Relational Calculus and Logic

Logic and Databases

From relational algebra to relational calculus, and other logic-database connections.

relational calculus logic syntax and semantics of first order logic parallels between first order logic and relational databases

Read [E&N §6.6, §6.7, §8.5.4] for more on todays stuff.

Procedural vs Declarative

Last week we saw relational algebra. Relational calculus is another formal database language, more like logic than algebra.

Procedural vs Declarative

Last week we saw relational algebra. Relational calculus is another formal database language, more like logic than algebra.

That is, relational calculus expressions say what you want, rather than how to find out.

Actually, its not black and white. Consider the differences between the following 3 equivalent queries.

Three different ways

SQL

SELECT bdate, address FROM employee WHERE salary > 50000

Three different ways

SQL

SELECT bdate, address FROM employee WHERE salary > 50000

relational algebra

πbdate,address(σ(salary> 50000 )(employee))

relational calculus (see [E&N, §6.6.1])

{t.fname, t.address | employee(t) ∧ t.salary > 50000 }

Relational Calculus Observations

{t.fname, t.address | employee(t) ∧ t.salary > 50000 }

it is based on “set-builder” notation

Relational Calculus Observations

{t.fname, t.address | employee(t) ∧ t.salary > 50000 }

it is based on “set-builder” notation variable t stands for a tuple attribute names are functions, writing t.fname for fname(t)

Relational Calculus Observations

{t.fname, t.address | employee(t) ∧ t.salary > 50000 }

it is based on “set-builder” notation variable t stands for a tuple attribute names are functions, writing t.fname for fname(t) relation names are predicates

Relational Calculus Observations

{t.fname, t.address | employee(t) ∧ t.salary > 50000 }

it is based on “set-builder” notation variable t stands for a tuple attribute names are functions, writing t.fname for fname(t) relation names are predicates

To make proper sense of this, we need to understand a bit about formal logic.

Logic101 in Ten Minutes

Logic

What is Logic? History of logic and computation Main ideas of logic: statement (syntax) situation (semantics) truth argument validity proof Syntax and semantics of first order logic (but not deduction)

What is Logic?

Logic is the study of good reasoning.

Is the reasoning in the following two examples good? Why, or why not?

Example 1

The drums are louder than the bass. The guitar is louder than the drums. Therefore, the guitar is louder than the bass.

Example 2

I told the bass player to turn it down or I’d punch his head in. Therefore, the guitar is louder than the bass.

What is Logic?

Logic is the study of good reasoning.

Is the reasoning in the following two examples good? Why, or why not?

Example 1

The drums are louder than the bass. The guitar is louder than the drums. Therefore, the guitar is louder than the bass.

Example 2

I told the bass player to turn it down or I’d punch his head in. Therefore, the guitar is louder than the bass.

Logic seeks theories of good reasoning, to give answers and explanations to questions like these.

Logic provides tools for precise work with ideas

Logic came from philosophers trying to understand, explain and even improve the certainty of mathematical arguments. Philosophers use formal logic to analyse concepts into more basic ideas, and solve problems caused by the confusion of English.

Logic provides tools for precise work with ideas

Logic came from philosophers trying to understand, explain and even improve the certainty of mathematical arguments. Philosophers use formal logic to analyse concepts into more basic ideas, and solve problems caused by the confusion of English.

Example 3

Nothing is better than a holiday in St Tropez. A ham sandwich is better than nothing. Thus, a ham sandwich is better than a holiday in St Tropez.