RELATIONAL CALCULUSTuple Relational CalculusWhat is Tuple Relational Calculus?Sample QueriesSample queries(cont….)Sample Queries(cont….)Formal DefinitionFormal definition(cont….)Building a formulaSafety of Expressions – The concept of domainDomain Relational CalculusSlide 12An atom in Domain Relational CalculusExample QueriesExample queries(cont….)Safety of ExpressionsSafety(cont….)PowerPoint PresentationSlide 19Slide 20What is Tuple Variables?EXAMPLESFree and Bound VariablesSlide 24RulesExampleQUANTIFIERSEXISTSSlide 29FORALLSlide 31More ExampleTARGET ITEM COMMALISTSWhat is the target item?ExamplesComputational CapabilitiesSlide 37Domain-Oriented Relational CalculusSlide 39Slide 40DEFINITION (cont’d)CONSTRUCTION OF RELATIONAL CALCULUSCONSTRUCTION OF RELATIONAL CALCULUS (cont’d)Slide 44WAY OF CONSTRUCTING A RELATIONAL CALCULUS EXPRESSIONWAY OF CONSTRUCTING A RELATIONAL CALCULUS EXPRESSION (cont’d)Slide 47SELECTION VIA A PREDICATESELECTION VIA A PREDICATE (cont’d)Slide 50Universal queriesUniversal queries (cont’d)DOMAIN RELATIONAL CALCULUSDOMAIN RELATIONAL CALCULUS (cont’d)VARIABLESVARIABLES (cont’d)CONTROL SUB-LANGUAGESCONTROL SUB-LANGUAGES (cont’d)Slide 59Slide 60Slide 61Slide 62SUMMARYRELATIONAL CALCULUSRELATIONAL CALCULUSProf. Sin-Min LeeProf. Sin-Min LeeDepartment of Computer Department of Computer ScienceScienceTuple Relational CalculusTuple Relational CalculusRelational model is based Relational model is based on the relational algebra, on the relational algebra, but we might equally well but we might equally well have said it is based on the have said it is based on the relational calculus. While relational calculus. While the algebra provides a the algebra provides a collection of explicit collection of explicit operations, the calculus operations, the calculus provides a notation for provides a notation for formulation the definition of formulation the definition of that desired relation in that desired relation in terms of those given terms of those given relations.relations.What is Tuple Relational What is Tuple Relational Calculus?Calculus?It is a non procedural query language: It is a non procedural query language: Describes the desired information Describes the desired information without giving a specific procedure for without giving a specific procedure for obtaining that information.obtaining that information.A query in tuple relational calculus is A query in tuple relational calculus is expresses as:expresses as: {t | P(t)}{t | P(t)} This represents a set of all tuples t such This represents a set of all tuples t such that predicate P is true for t.that predicate P is true for t.Sample QueriesSample QueriesFinding the branch – name, loan – Finding the branch – name, loan – number, and amount for loans of over number, and amount for loans of over $ 1200$ 1200 {t | t {t | t loan loan ٨٨ t[amount] > 1200}t[amount] > 1200}In English this query would mean: The In English this query would mean: The set of tuples t where t belongs to the set of tuples t where t belongs to the loan relation and the loan amount for loan relation and the loan amount for each t is greater than $ 1200.each t is greater than $ 1200.Sample queries(cont….)Sample queries(cont….)Finding the loan – number for each loan of Finding the loan – number for each loan of an amount greater than $1200.an amount greater than $1200. {t | {t | s s loan (t[loan – number] = loan (t[loan – number] = s[loan – number] s[loan – number] ۸۸ s[amount > 1200)}s[amount > 1200)} In English we would read the preceding In English we would read the preceding statement as “ The set of all tuples t such statement as “ The set of all tuples t such that there exists a tuple s in relation loan for that there exists a tuple s in relation loan for which the values of t and s for the loan – which the values of t and s for the loan – number attribute are equal, and the value of number attribute are equal, and the value of s for the amount attribute is greater than s for the amount attribute is greater than $1200.”$1200.”Sample Queries(cont….)Sample Queries(cont….)The expression:The expression: {t | {t | r r customer (r[customer – name] = customer (r[customer – name] = t[customer – name]) t[customer – name]) ٨٨ (( u u branch (u[branch – branch (u[branch – city] = Brooklyn” city] = Brooklyn” s s depositor (t[customer – depositor (t[customer – name] = s[customer – name] name] = s[customer – name] w w account account (w[account – number- = s[account – number] (w[account – number- = s[account – number] ٨٨ w[branch – name] = u[branch – name]))))}w[branch – name] = u[branch – name]))))} In English, would mean “The set of all customers( i.e In English, would mean “The set of all customers( i.e customer name tuples t) such that for all tuples u in the customer name tuples t) such that for all tuples u in the branch relation, if the value of u on attribute branch – branch relation, if the value of u on attribute branch – city is Brooklyn, then the customer has an account at city is Brooklyn, then the customer has an account at the branch whose name appears in the branch name the branch whose name appears in the branch name attribute of u”attribute of u”Formal DefinitionFormal DefinitionAs shown earlier, a tuple relational calculus expression is As shown earlier, a tuple relational calculus expression is of the formof the form {t | P(t)}{t | P(t)} Where P is a formula.Where P is a formula.A formula may contain several tuple variables.A formula may contain several tuple variables.A tuple variable is said to be a free variable unless it is A tuple variable is said to be a free variable unless it is quantified by a quantified by a З(there exists) or Џ(for all).З(there exists) or Џ(for all).Tuple variables that are quantified by Tuple variables that are quantified by З or Џ are called З or Џ are called bound variables.bound variables.For ex, in the expression:For ex, in the expression: t t loan loan ٨٨ s s customer(t[branch – name] = customer(t[branch – name] = s[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
View Full Document