RELATIONAL CALCULUS Prof. Sin-Min Lee Department of Computer Science.

Slides:



Advertisements
Similar presentations
Relational Calculus and Datalog
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
D ATABASE S YSTEMS I R ELATIONAL A LGEBRA. 22 R ELATIONAL Q UERY L ANGUAGES Query languages (QL): Allow manipulation and retrieval of data from a database.
Relational Algebra Dashiell Fryer. What is Relational Algebra? Relational algebra is a procedural query language. Relational algebra is a procedural query.
Ver 1,12/09/2012Kode :CCs 111,Sistem basis DataFASILKOM Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. ©Silberschatz, Korth and.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Relational Calculus Ameetinder Singh CS 157A. Tuple Relational Calculus  non-procedural query language as compared to relational algebra that is procedural.
Relational Calculus CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth   We will occasionally use this arrow notation unless there is danger of.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C6.
Relational Calculus CS 186, Fall 2003, Lecture 6 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
Rutgers University Relational Calculus 198:541 Rutgers University.
Relational Algebra.  Introduction  Relational Algebra Operations  Projection and Selection  Set Operations  Joins  Division  Tuple Relational Calculus.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
Relational Calculus R&G, Chapter 4. Relational Calculus Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). Calculus.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
Relational Algebra.
The Relational Calculus (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 5: Other Relational Languages.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.
Computing & Information Sciences Kansas State University Wednesday, 17 Sep 2008CIS 560: Database System Concepts Lecture 9 of 42 Wednesday, 18 September.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
Chapter 3: Relational Model III Additional Relational Algebra Operations Additional Relational Algebra Operations Views Views.
Relational Calculus. Relational calculus query specifies what is to be retrieved rather than how to retrieve it. – No description of how to evaluate a.
Relational Calculus Chapter 4, Section 4.3.
Chapter 8 Relational Calculus.
Relational Algebra & Calculus
Module 2: Intro to Relational Model
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Relational Calculus Chapter 4, Part B
Chapter 3: Relational Model III
Chapter 6: Formal Relational Query Languages
Chapter 2: Intro to Relational Model
Lecture 4 of 42 Relational Joins Wednesday, 30 January 2008
Chapter 6: Formal Relational Query Languages
Instructor: Mohamed Eltabakh
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 6: Formal Relational Query Languages
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Relational Algebra & Calculus
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Calculus Chapter 4, Part B
CS 405G: Introduction to Database Systems
Presentation transcript:

RELATIONAL CALCULUS Prof. Sin-Min Lee Department of Computer Science

Tuple Relational Calculus Relational model is based on the relational algebra, but we might equally well have said it is based on the relational calculus. While the algebra provides a collection of explicit operations, the calculus provides a notation for formulation the definition of that desired relation in terms of those given relations.

What is Tuple Relational Calculus? n It is a non procedural query language: Describes the desired information without giving a specific procedure for obtaining that information. n A query in tuple relational calculus is expresses as: {t | P(t)} {t | P(t)} This represents a set of all tuples t such that predicate P is true for t. This represents a set of all tuples t such that predicate P is true for t.

Sample Queries n Finding the branch – name, loan – number, and amount for loans of over $ 1200 {t | t  loan ٨ t[amount] > 1200} {t | t  loan ٨ t[amount] > 1200} n In English this query would mean: The set of tuples t where t belongs to the loan relation and the loan amount for each t is greater than $ 1200.

Sample queries(cont….) n Finding the loan – number for each loan of an amount greater than $1200. {t |  s  loan (t[loan – number] = s[loan – number] ۸ s[amount > 1200)} {t |  s  loan (t[loan – number] = s[loan – number] ۸ s[amount > 1200)} In English we would read the preceding statement as “ The set of all tuples t such that there exists a tuple s in relation loan for which the values of t and s for the loan – number attribute are equal, and the value of s for the amount attribute is greater than $1200.” In English we would read the preceding statement as “ The set of all tuples t such that there exists a tuple s in relation loan for which the values of t and s for the loan – number attribute are equal, and the value of s for the amount attribute is greater than $1200.”

Sample Queries(cont….) n The expression: {t |  r  customer (r[customer – name] = t[customer – name]) ٨ (  u  branch (u[branch – city] = Brooklyn”  s  depositor (t[customer – name] = s[customer – name]   w  account (w[account – number- = s[account – number] ٨ w[branch – name] = u[branch – name]))))} {t |  r  customer (r[customer – name] = t[customer – name]) ٨ (  u  branch (u[branch – city] = Brooklyn”  s  depositor (t[customer – name] = s[customer – name]   w  account (w[account – number- = s[account – number] ٨ w[branch – name] = u[branch – name]))))} In English, would mean “The set of all customers( i.e customer name tuples t) such that for all tuples u in the branch relation, if the value of u on attribute branch – city is Brooklyn, then the customer has an account at the branch whose name appears in the branch name attribute of u” In English, would mean “The set of all customers( i.e customer name tuples t) such that for all tuples u in the branch relation, if the value of u on attribute branch – city is Brooklyn, then the customer has an account at the branch whose name appears in the branch name attribute of u”

Formal Definition n As shown earlier, a tuple relational calculus expression is of the form {t | P(t)} {t | P(t)} Where P is a formula. Where P is a formula. n A formula may contain several tuple variables. n A tuple variable is said to be a free variable unless it is quantified by a З(there exists) or Џ(for all). n Tuple variables that are quantified by З or Џ are called bound variables. n For ex, in the expression: t  loan ٨  s  customer(t[branch – name] = s[branch – name]) t  loan ٨  s  customer(t[branch – name] = s[branch – name]) t is a free variable and s is a bound variable. t is a free variable and s is a bound variable.

Formal definition(cont….) n A formula in relational calculus is made up of atoms. n An atom has one of the following forms. 1. S Є r, where s is a tuple variable and r is a relation. 2. S[x] © u[y], where s and u are tuple variables, x is an attribute on which s is defined, y is an attribute on which u is defined, and © is the comparison operator. It is required that x and y have domains that can be compared using ©. 3. S[x] © c, where s is a tuple variable, x is an attribute on which s is defined, © is a comparison operator, and c is a constant in the domain of x.

Building a formula We build up a formula from atoms by using the following rules. We build up a formula from atoms by using the following rules. n An atom is a formula. n If P1 is a formula, then so are ¬P1 and (P1). n If P1 and P2 are formulae, then so are P1 ٧ P2, P1 ٨ P2, and P1 => P2. n If P1(s) is a formula containing a free tuple variable s, and r is a relation, then  s  r(P1(s)) and  s  (P1(s))  s  r(P1(s)) and  s  (P1(s)) are also formulae are also formulae

Safety of Expressions – The concept of domain n A tuple relational calculus may generate an infinite relation. For ex: {t | ¬(t  loan)} {t | ¬(t  loan)} There are infinitely many tuples that are not in loan. There are infinitely many tuples that are not in loan. n To address this issue, we use the concept of domain of tuple relational formula, P. The domain of P, denoted dom(P), is a set of all value referenced by P.These include values mentioned in P itself, as well as the values that appear in a tuple of a relation mentioned in P. The domain of P, denoted dom(P), is a set of all value referenced by P.These include values mentioned in P itself, as well as the values that appear in a tuple of a relation mentioned in P. For ex: dom(t  loan ٨ t[amount] > 1200) is the set containing 1200 as well as set of all values appearing in loan. For ex: dom(t  loan ٨ t[amount] > 1200) is the set containing 1200 as well as set of all values appearing in loan.

Domain Relational Calculus This is the second form of relational calculus n Uses domain variables that take on values from an attribute domain, rather than values for an entire tuple. n Closely related to tuple relational calculus.

Formal Definition n A general expression in Domain relational calculus is of the form { | P(x1,x2,….,xn)} { | P(x1,x2,….,xn)} where x1, x2,….,xn represent domain variables. P represents a formula composed of atoms, as was the case in tuple relational calculus. where x1, x2,….,xn represent domain variables. P represents a formula composed of atoms, as was the case in tuple relational calculus.

An atom in Domain Relational Calculus An atom in domain relational calculus has one of the following forms: An atom in domain relational calculus has one of the following forms: n  r, where r is a relation on n attributes and x1, x2, ….,xn are domain values or domain constraints. n X © y, where x and y are domain values, and © is a comparison operator (,>=). We require that attributes x and y have domains that can be compared by ©. n X © c, where x is a domain variable, © is a comparison operator, and c is a constant in the domain of the attribute for which x is a domain variable.

Example Queries n Find the loan number, branch name, and amount for loans over $1200. { |  loan ٨ a > 1200} { |  loan ٨ a > 1200} n Find all loan numbers for loans with an amount > 1200: { |  b,a (  loan ٨ a > 1200)} { |  b,a (  loan ٨ a > 1200)} n When we write  b in domain calculus, b refers not to a tuple, but rather to a domain value. n The domain of b is unconstrained(unlike as in relational tuple calculus) until the sub formula  loan constraints b to branch names that appear in the loan relation.

Example queries(cont….) n Find the names of all customers who have an account at all branches located in Brooklyn: { |  n(  customer) ٨  x,y,z (  branch ٨ y = “Brooklyn” =>  a,b(  account ٨  depositor))} { |  n(  customer) ٨  x,y,z (  branch ٨ y = “Brooklyn” =>  a,b(  account ٨  depositor))} In English, we interpret this expression as “The set of all(customer name) tuples c such that, for all (branch – name, branch – city, assets) tuples, x,y,z, if the branch city is Brooklyn, then the following is true: In English, we interpret this expression as “The set of all(customer name) tuples c such that, for all (branch – name, branch – city, assets) tuples, x,y,z, if the branch city is Brooklyn, then the following is true: 1. There exists a tuple in the relation account with account number a and branch name x. 2. There exists a tuple in the relation depositor with customer c and account number a.”

Safety of Expressions n As noted in tuple relational calculus expressions in the domain relational calculus may also generate an infinite relation. For ex: {{ | ¬ (  loan)} {{ | ¬ (  loan)} is unsafe, because it allows values in the result that are not in the domain of the expression. is unsafe, because it allows values in the result that are not in the domain of the expression.

Safety(cont….) An expression: An expression: { | P(x1,x2,….,xn)} { | P(x1,x2,….,xn)} is safe if all of the following hold. is safe if all of the following hold. n All values that appear in tuples of the expression are values from dom(P). n For every “there exists” subformula of the form Э x(P1(x)), the sub formula is true only if and only if there is a value x in dom(P1) such that P1(x) is true. n For every “for all” subformula of the form  x(P1(x)), the subformula is true if and only if P1(x) is true for all values of x from dom(P1).

n Introduction n Tuple-Oriented Relational Calculus n Computational Capabilities n Domain-Oriented Relational Calculus

The calculus simply describes what the problem is, the algebra prescribes a procedure for solving that problem. Or we can say the algebra and the calculus are precisely equivalent to one another, because for every expression of the algebra, there is an equivalent expression in the calculus.

Relational calculus is founded on a branch of mathematical logic called the predicate calculus. The fundamental feature of the calculus as defined in reference is the notion of the tuple variable.

What is Tuple Variables? A tuple variable is a variable that “range over” a named relation: that is a variable whose only permitted values are tuples of the relation.

EXAMPLES To specify the range of a tuple variable T as the Staff relation, we write: RANGE OF T IS STAFF To express the the query ‘Find the set of all tuples T such that P(T) is true’ we can write { T | P(T) }

Free and Bound Variables Each occurrence of a tuple variable within a WFF ( Well- Formed Formula) is either free or bound. Here we mean an appearance of the variable name within the WFF under consideration.

A tuple variable T occurs within a WFF either in the context of an attribute context of an attribute reference of the form T.A (where A is an attribute of the relation over which T ranges) or as the variable immediately following one of the quantifiers EXISTS and FORALL

Rules n Within a simple comparison such as “T.A < U.A” all occurrences are free “T.A < U.A” all occurrences are free n Occurrences in the WFFs “(f)” and “NOT f” are free or bound according as they are free or bound in f. Occurrences in the WFFs “f AND g”, “NOT f” are free or bound according as they are free or bound in f. Occurrences in the WFFs “f AND g”, “f OR g”, and “IF f THEN g” are free or bound according as they are free or bound in f or g “f OR g”, and “IF f THEN g” are free or bound according as they are free or bound in f or g

Example n Simple Comparison: SX.S= = ‘S1’ SX.S= = ‘S1’ (Range of SX is S) here occurrence SX is free (Range of SX is S) here occurrence SX is free n Boolean WFFs: - PX.WEIGHT 25 - PX.WEIGHT 25 - NOT ( SX.CITY = ‘London’ ) - NOT ( SX.CITY = ‘London’ ) here PX and SX are free here PX and SX are free

QUANTIFIERS There are two quantifiers: 1/ EXISTS 1/ EXISTS 2/ FORALL 2/ FORALL

EXISTS EXISTS x (f) means there exists at least one value of the variable x such that the WFF f evaluates to true. If f is a WFF in which variable x is free and bound in f EXISTS x (f) means there exists at least one value of the variable x such that the WFF f evaluates to true. If f is a WFF in which variable x is free and bound in f

Example Let relation R contain the following tuples ( 1, 2, 3 ); ( 1, 2, 4 ); ( 1, 3, 4 ) ( 1, 2, 3 ); ( 1, 2, 4 ); ( 1, 3, 4 ) EXISTS T ( T[3] > 1 ) : true EXISTS T ( T[3] > 1 ) : true EXISTS T ( T[2] > 3 ) : false EXISTS T ( T[2] > 3 ) : false EXISTS T ( T[1] > 1 OR T[3] = 4 true EXISTS T ( T[1] > 1 OR T[3] = 4 true

FORALL FORALL FORALL x ( f ) means: For all values of the variable x, the WFF f evaluates are true.

Example FORALL PX ( PX.COLOR = ‘Red’ ) This WFF can be read as : For all P tuples, PX say, the COLOR value in that tuple is Red. ( The occurrence of PX in this example is bound)

More Example Let relation R contain the following tuples ( 1, 2, 3 ); ( 1, 2, 3 ); ( 1, 3, 4 ) ( 1, 2, 3 ); ( 1, 2, 3 ); ( 1, 3, 4 ) FORALL T ( T[1] > 1 )false FORALL T ( T[2] > 1 ) true FORALL T ( T[1] = 1 AND T[3] > 2 ) true true

TARGET ITEM COMMALISTS Each target item in a target item commalist is either a simple variable name such as T.A [ AS X ] Here T is a tuple variable, A is an attribute of the associated relation, and X is an attribute name for the corresponding attribute in the result of evaluating the target item commalist

What is the target item? Target Item that is just a variable name T is defined to be shorthand for the commalist of target items T.A1, T.A2, T.A3,……, T.An where A1, A2, … An are all of the attributes of the relation associated with T

Examples - ( SX.S# ) - ( SX.S# AS SNO ) - ( SX.S# AS SNO ) WHERE SX.CITY = ‘London’ SX.CITY = ‘London’ - ( SX.S# ) WHERE SX.CITY = ‘London’

Computational Capabilities We just simply extend the definition of comparands and to include a new category, scalar- expression, where the operands of such an expression in turn can include literal, attribute references, and/or aggregate function references. We just simply extend the definition of comparands and target-items to include a new category, scalar- expression, where the operands of such an expression in turn can include literal, attribute references, and/or aggregate function references.

Aggregate-Function is COUNT, SUM, AVG, MAX, or MIN Syntax for aggregate-function reference: aggregate-function (expression[,attribute]) * expression is an expression of the tuple calculus, and attribute is that attribute of that result relation over which the aggregation is to be done

Domain-Oriented Relational Calculus

In domain-oriented relational calculus, we use variables that take their values from domain instead of tuples of relations. In the domain-oriented relational calculus, we often want to test for a membership condition, to determine whether values belong to a relation.

Examples - ( SX ) denotes the set of all supplier numbers denotes the set of all supplier numbers - ( SX ) WHERE S ( S#: SX ) denotes the set of all supplier numbers in relation S denotes the set of all supplier numbers in relation S - ( SX ) WHERE S ( S#:SX, CITY: ‘London’ denotes that subset of those supplier numbers for which the city is London denotes that subset of those supplier numbers for which the city is London

DEFINITION (cont ’ d) n Target list: A condition in a relational calculus statement that restricts membership in a solution relation. n Existential quantifier: Relational calculus expression affirming the existence of a at least one row to which a condition applies. n Universal quantifier: Relational calculus expression stating that some condition applies to every row of some type.

CONSTRUCTION OF RELATIONAL CALCULUS In Relational Calculus, queries or expressions, are constructed as well-formed formulas. A well-formed formula (WFF) is an expression composed ultimately of atomic predicates. A WFF is itself a predicate, which assumes a true or false value depending on the argument values in its constituent atomic predicates. In Relational Calculus, queries or expressions, are constructed as well-formed formulas. A well-formed formula (WFF) is an expression composed ultimately of atomic predicates. A WFF is itself a predicate, which assumes a true or false value depending on the argument values in its constituent atomic predicates.

CONSTRUCTION OF RELATIONAL CALCULUS (cont ’ d) Figure 4.1 Truth tables for logical operators

CONSTRUCTION OF RELATIONAL CALCULUS (cont ’ d) For example, if a, b are two WFFs, then (a  b) is also a WFF. (a  b) is true for precisely those argument values of a and b for which both a and b are true. Figure 4.1 gives the basic set of logical operators that can be used to produce new WFFs from existing WFFs; it also shows the truth values of the new WFF as a consequence of the truth values of the components.

WAY OF CONSTRUCTING A RELATIONAL CALCULUS EXPRESSION We can construct a relational-calculus expression, or WFF, in the following ways: A predicate P is a WFFA predicate P is a WFF If P is a WFF, then so are (P) and ~(P)If P is a WFF, then so are (P) and ~(P) If P1 and P2 are WFF ’ s, then so are (P1  P2) andIf P1 and P2 are WFF ’ s, then so are (P1  P2) and (P1 V P2) (P1 V P2)

WAY OF CONSTRUCTING A RELATIONAL CALCULUS EXPRESSION (cont ’ d) If P is WFF in which t occurs as a free variable, thenIf P is WFF in which t occurs as a free variable, then so are  t(P) and  t(P) so are  t(P) and  t(P) nothing else is a WFFnothing else is a WFF Symbols  and  are called quantifiers. Symbol  is called the existential quantifier and is interpreted or read as “ three exists ” and  is called the universal quantifier and interpreted as “ for all. ”

WAY OF CONSTRUCTING A RELATIONAL CALCULUS EXPRESSION (cont ’ d) An example of existential quantification: Q(w, x) =  ( y, z)(P(w, x, y, z)) n (w, x) is a fixed pair n If P(w, x, y, z) is true for some choice of a (y, z) pair, Q(w, x) is true. n Otherwise it is false. n w, x, y, z are free variables in P(w, x, y, z) n However, y and z are not free variables in the expression (  y, z)(P(w, x, y, z))

SELECTION VIA A PREDICATE The following example: {t |tank(t)  tcolor(t) = “ red ” } n The automatic predicate tank(t) responds true when the tuple t is element of the tank relation The function tcolor(t) returns the tcolor value of the tuple t, and the atomic predicate tcolor(t) = “ red ” tests the returned value against a constant. The function tcolor(t) returns the tcolor value of the tuple t, and the atomic predicate tcolor(t) = “ red ” tests the returned value against a constant. n Therefore the complete predicate (WFF) isolates the tuples corresponding to red tanks.

SELECTION VIA A PREDICATE (cont ’ d) The need for two types of atomic predicates: n The first type tests membership in some named relation. Each table in the data base gives rise to an atomic predicate of the same name, which takes one argument. The predicate returns true when the argument is a tuple within the table, and it returns false in all other cases. For example, tank(t) is true when the tuple t is an element of the tank relation, and it ’ s false otherwise. For example, tank(t) is true when the tuple t is an element of the tank relation, and it ’ s false otherwise.

SELECTION VIA A PREDICATE (cont ’ d) The second type of atomic predicate permits judgments about the attribute values within tuples. When the argument is a tuple that contains an association over the named attribute, the the function returns the corresponding value. If the tuple doesn ’ t contain such an association, then the function returns the value null. The second type of atomic predicate permits judgments about the attribute values within tuples. When the argument is a tuple that contains an association over the named attribute, the the function returns the corresponding value. If the tuple doesn ’ t contain such an association, then the function returns the value null. For example, tcolor(t) returns the tcolor value of the tuple t, that is, red, blue, or green, if t contains a tcolor value. Otherwise, tcolor(t) returns null.

Universal queries Relational calculus expresses a universal query by assigning free variables to the relation providing the candidates. It then introduces a universally quantified component, stating (  t)((t is an anchor) => (t is reachable from the candidate)) To find the names of species represented in all tanks that contain representatives of all species with a diet of worms. Follow a stepwise construction proceeds: Q = {sname(s) | species(s)  (  t)(P1(t) => (  f)(fish(f)  snow(f) = snow(s)  tno(f) = tno(t)))}  snow(f) = snow(s)  tno(f) = tno(t)))}

Universal queries (cont ’ d) if P1(t) is true when t is a tank that contains all the wormy species. P1(t) = tank(t)  (  s1)(P2(s1) => (  f1)(fish(f1)  snow(f1) = snow(s1)  tno(f1) = tno(t)))  snow(f1) = snow(s1)  tno(f1) = tno(t))) P2(s1) is true when s1 is a wormy species. Therefore, P2(s1) = species(s1)  sfood(s1) = “ worms ” Substituting P2 into P1 and P1 into Q give a single WFF that effectively filters the database for the requested species names.

DOMAIN RELATIONAL CALCULUS In domain relational calculus the variables range over a pool of values, the union of all domains in the database schema. The atomic predicates permit table membership tests on assembled tuples, and they allow direct  -comparisons between the variables For example, the following expression requests the names of red tanks {x | (  w, y) (tank(tno = w, tname = x, tcolor = “ red ”, tvolume = y))}

DOMAIN RELATIONAL CALCULUS (cont ’ d) {x | ( w, y) (tank(tno = w, tname = x, tcolor = “ red ”, tvolume = y))} For a fixed candidate x, the variables w and y range over the pool of elements in the common domain and attempt to lock on to value such that the assembled tuple appears in the tank relation. If w and y can achieve such values, x is the name of a red tank.

VARIABLES A variables is free if it is not within the scope of a quantifier, otherwise, it is a bound variable. Restricting the scope of tuple variable is important. For example, r(a)  5 may trigger the searching of the entire world, that is, there is no end to values that are not equal to 5.

VARIABLES (cont ’ d) We can fix the problem in two ways: Add a range (scope) declaration before the WFF.Add a range (scope) declaration before the WFF. Add a predicate into the WFF that expressesAdd a predicate into the WFF that expresses r  R, i.e.., tuple variable r belong to relation R. r  R, i.e.., tuple variable r belong to relation R. The above methods guarantee us termination of the search process since we do not have to search beyond the relation itself.

CONTROL SUB-LANGUAGES Definition The Control Sub-Languages have been provided to allow users to access and control an Information System. In their simplest form they allow users to create, read, update, and destroy information held in that system, and furthermore they can be used to read, create, update, and destroy the description of that system.

CONTROL SUB-LANGUAGES (cont ’ d) In addition to these commonplace tasks, the language provides a set of powerful tools to allow users to identify the information that they require, thus ensuring that they do not have to bother with unnecessary details. Design Control Sub-Language: It is virtually impossible to design a standard language which

CONTROL SUB-LANGUAGES (cont ’ d) can be used successfully by all those who might wish to interact with an Information System. however, it is possible to design a basic language which satisfies the majority of users and to provide extensions to that basic language. This is the approach which has been adopted with the Control Sub Language.

CONTROL SUB-LANGUAGES (cont ’ d) Manipulating Entity Sets: The descriptions above tell us how Control Sub- Language provides facilities for a user to transfer information between a given entity set and this terminal. This works well providing the user whishes to access the whole of a single set.

CONTROL SUB-LANGUAGES (cont ’ d) However, if the user whishes to do more than this, then the user has, implicitly or explicitly, to create a new temporary set. This temporary set exists within the user ’ s work space and is linked to the entity sets of the Information Environment by the successive use of the relational operators.

CONTROL SUB-LANGUAGES (cont ’ d) These operators are: n Projection: {r[A]:r  R} n Union: {t:t  R V t  S} n Difference: {t:t  R  t  S} n Cartesian product: {(r || s) : r  R  s  S} n Selection: {r:r  R  (r[A]  opr)} where opr is V or r[B] n Intersection: {t:t  R  t  S} n Join: {r || s): r  R  s  S (r[A]  s[B])} n Division: {r[A]: r  R  s[B]  (r[A]} where (r[A]) are all tuples in r[A]. (r[A]) are all tuples in r[A].

SUMMARY Tuple-Oriented Relational Calculus Computational Capabilities Domain-Oriented Relational Calculus