Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Tuple and Domain Relational Calculus and Other DB Languages, Study notes of Database Management Systems (DBMS)

An overview of relational database languages, focusing on tuple and domain relational calculus. It covers the objectives of relational calculus, the concept of tuple variables, and the use of quantifiers in tuple relational calculus. The document also introduces domain relational calculus and other database languages, including transform-oriented languages and query-by-example (qbe).

Typology: Study notes

2010/2011

Uploaded on 09/08/2011

rossi46
rossi46 🇬🇧

4.5

(10)

313 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DBDI / Rel Calculus 30/05/2007
Lecture 7 1
DBDI/ Lecture 7
Relational DB Languages
Relational Calculus & Other DB
Languages
Dr. Ala Al-Zobaidie
The slides are based on the textbook Database Systems by Connolly & Begg
30/05/2007 DBDI / Rel Calculus 2
Lecture’s Objectives
How to form queries in tuple relational
calculus.
How to form queries in domain relational
calculus.
Other DB Languages
30/05/2007 DBDI / Rel Calculus 3
Relational Calculus
If predicate contains a variable (e.g. ‘xis
a member of staff’), there must be a
range for x.
When we substitute some values of this
range for x, proposition may be true; for
other values, it may be false.
When applied to databases, relational
calculus has forms: tuple and domain.
30/05/2007 DBDI / Rel Calculus 4
Tuple Relational Calculus
Interested in finding tuples for which a predicate
is true. Based on use of tuple variables.
Tuple variable is a variable that ‘ranges over’ a
named relation: ie., variable whose only permitted
values are tuples of the relation.
Specify range of a tuple variable Sas the Staff
relation as:
Staff(S) Range of S is the Staff table
To find set of all tuples S such that P(S) is true:
{S | P(S)}
30/05/2007 DBDI / Rel Calculus 5
Tuple Relational Calculus - Example
To find details of all staff earning more
than £10,000:
{S | Staff(S) S.salary > 10000}
To find a particular attribute, such as
salary, write:
{S.salary | Staff(S) S.salary > 10000}
If true produce S
30/05/2007 DBDI / Rel Calculus 6
Tuple Relational Calculus
Can use two quantifiers to tell how many
instances the predicate applies to:
Existential quantifier (‘there exists’)
Universal quantifier (‘for all’)
Tuple variables qualified by or are
called bound variables, otherwise called free
variables.
pf3
pf4

Partial preview of the text

Download Understanding Tuple and Domain Relational Calculus and Other DB Languages and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

DBDI/ Lecture 7

Relational DB Languages

Relational Calculus & Other DB Languages Dr. Ala Al-Zobaidie The slides are based on the textbook Database Systems by Connolly & Begg 30/05/2007 DBDI / Rel Calculus 2

Lecture’s Objectives

• How to form queries in tuple relational

calculus.

• How to form queries in domain relational

calculus.

• Other DB Languages

30/05/2007 DBDI / Rel Calculus 3

Relational Calculus

• If predicate contains a variable (e.g. ‘ x is

a member of staff’), there must be a

range for x.

• When we substitute some values of this

range for x , proposition may be true; for

other values, it may be false.

• When applied to databases, relational

calculus has forms: tuple and domain.

30/05/2007 DBDI / Rel Calculus 4

Tuple Relational Calculus

  • Interested in finding tuples for which a predicate is true. Based on use of tuple variables.
  • Tuple variable is a variable that ‘ranges over’ a named relation: ie., variable whose only permitted values are tuples of the relation.
  • Specify range of a tuple variable S as the Staff relation as: Staff(S) Range of S is the Staff table
  • To find set of all tuples S such that P(S) is true: {S | P(S)}

Tuple Relational Calculus - Example

• To find details of all staff earning more

than £10,000:

{S | Staff(S) ∧ S.salary > 10000}

• To find a particular attribute, such as

salary, write:

{S.salary | Staff(S) ∧ S.salary > 10000}

If true produce S

Tuple Relational Calculus

• Can use two quantifiers to tell how many

instances the predicate applies to:

  • Existential quantifier ∃ (‘there exists’)
  • Universal quantifier ∀ (‘for all’)

• Tuple variables qualified by ∀ or ∃ are

called bound variables, otherwise called free

variables.

30/05/2007 DBDI / Rel Calculus 7

Tuple Relational Calculus

• Existential quantifier used in formulae that

must be true for at least one instance, such

as:

Staff(S) ∧ (∃B)(Branch(B) ∧ (B.branchNo = S.branchNo) ∧ B.city = ‘London’)

• Means ‘There exists a Branch tuple

that has the same branchNo as the

branchNo of the current Staff tuple, S ,

and is located in London’.

30/05/2007 DBDI / Rel Calculus 8

Tuple Relational Calculus

• Universal quantifier is used in statements

about every instance, such as:

(∀B) (B.city ≠ ‘Paris’)

• Means ‘For all Branch tuples, the address is

not in Paris’.

• Can also use ~(∃B) (B.city = ‘Paris’) which

means ‘There are no branches with an

address in Paris’.

30/05/2007 DBDI / Rel Calculus 9

Tuple Relational Calculus

  • Formulae should be unambiguous and make sense.
  • A (well-formed) formula is made out of atoms:
    • R(S (^) i) , where S (^) i is a tuple variable and R is a relation
    • S (^) i .a 1 θ S (^) j .a (^2)
    • S (^) i .a 1 θ c
  • Can recursively build up formulae from atoms:
    • An atom is a formula
    • If F 1 and F 2 are formulae, so are their conjunction, F 1 ∧ F 2 ; disjunction, F 1 ∨ F 2 ; and negation, ~ F 1
    • If F is a formula with free variable X , then (∃ X) ( F ) and (∀ X) ( F ) are also formulae.

30/05/2007 DBDI / Rel Calculus 10

a) List the names of all managers who earn

more than £25,000.

{S.fName, S.lName | Staff(S) ∧ S.position = ‘Manager’ ∧ S.salary > 25000}

b) List the staff who manage properties for rent

in Glasgow.

{S | Staff(S) ∧ (∃P) (PropertyForRent(P) ∧ (P.staffNo = S.staffNo) ∧ P.city = ‘Glasgow’)}

Example - Tuple Relational Calculus

Condition

Target tuple variables Range

Example - Tuple Relational Calculus

c) List the names of staff who currently do not

manage any properties.

{S.fName, S.lName | Staff(S) ∧ (~(∃P) (PropertyForRent(P)∧(S.staffNo = P.staffNo)))}

Or

{S.fName, S.lName | Staff(S) ∧ (∀P) (~PropertyForRent(P) ∨ ~(S.staffNo = P.staffNo)))}

Example - Tuple Relational Calculus

• List the names of clients who have viewed a

property for rent in Glasgow.

{C.fName, C.lName | Client(C) ∧ ((∃ V )(∃ P ) (Viewing(V) ∧ PropertyForRent(P) ∧ (

C.clientNo = V.clientNo) ∧

(V.propertyNo=P.propertyNo)∧P.city =‘Glasgow’))}

30/05/2007 DBDI / Rel Calculus 19

Domain Relational Calculus

• When restricted to safe expressions,

domain relational calculus is equivalent to

tuple relational calculus restricted to safe

expressions, which is equivalent to

relational algebra.

• Means every relational algebra expression

has an equivalent relational calculus

expression, and vice versa.

30/05/2007 DBDI / Rel Calculus 20

Other Languages

  • Transform-oriented languages are non- procedural languages that use relations to transform input data into required outputs (e.g. SQL).
  • Graphical languages provide user with picture of the structure of the relation. User fills in example of what is wanted and system returns required data in that format (e.g. QBE).

30/05/2007 DBDI / Rel Calculus 21

Query-by-Example (QBE)

• Visual approach for accessing information in

a database through use of query templates.

• When user constructs a QBE - in

background, DBMS creates an equivalent

SQL statement.

• Allows user to perform many operations

30/05/2007 DBDI / Rel Calculus 22

Microsoft Access Query Types

  • Select Query
  • Aggregate Query
  • Parameter Query
  • Find Matched/ Unmatched Query
  • Crosstab Query
  • Auto-lookup Query
  • Action Query (data modification & structure definition)
  • SQL Query (data retrieval)

Other Languages

• 4GLs can create complete customized

application using limited set of commands

in a user-friendly, often menu-driven

environment.

• Some systems accept a form of natural

language , sometimes called a 5GL, although

this development is still a an early stage.

Summary

• Relational tuple Calculus

• Relational Domain Calculus

• Other Languages