This document summarizes relational calculus, which combines tuple calculus and domain calculus. Tuple calculus uses tuple variables that represent individual tuples from a relation. Domain calculus uses domain variables that represent attribute values. Relational calculus expressions specify what to retrieve rather than how, making it a nonprocedural language. The document defines well-formed formulas, free and bound variables, quantifiers, and safe expressions. It also distinguishes relational calculus from relational algebra, noting they have equivalent expressive power but different procedural/nonprocedural nature. Self-assessment and multiple choice questions follow with answers provided.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
42 views8 pages
Unit 7 Relational Calculus: Structure
This document summarizes relational calculus, which combines tuple calculus and domain calculus. Tuple calculus uses tuple variables that represent individual tuples from a relation. Domain calculus uses domain variables that represent attribute values. Relational calculus expressions specify what to retrieve rather than how, making it a nonprocedural language. The document defines well-formed formulas, free and bound variables, quantifiers, and safe expressions. It also distinguishes relational calculus from relational algebra, noting they have equivalent expressive power but different procedural/nonprocedural nature. Self-assessment and multiple choice questions follow with answers provided.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8
Database Management Systems Unit 7
Sikkim Manipal University Page No.: 120
Unit 7 Relational Calculus Structure 7.1 Introduction Objectives Self Assessment Question(s) (SAQs) 7.2 Tuple Relational Calculus Self Assessment Question(s) (SAQs) 7.3 Domain Relational Calculus Self Assessment Question(s) (SAQs) 7.4 Summary 7.5 Terminal Questions (TQs) 7.6 Multiple Choice Questions (MCQs) 7.7 Answers to SAQs, TQs, and MCQs 7.7.1 Answers to Self Assessment Question(s) (SAQs) 7.7.2 Answers to Terminal Question(s) (TQs) 7.7.3 Answers to Multiple Choice Questions (MCQs) 7.1 Introduction Relational calculus is the combination of tuple calculus and domain calculus. In relational calculus, a query is expressed as a formula or an expression consisting of variables. In tuple calculus, variables may take an individual tuple from a specified relation as its value. In domain calculus, the variable may take values from a specified domain (attribute) as its value. Relational calculus is a nonprocedural language because it specifies what is to be retrieved rather than how to retrieve it. In this we write one declarative expression to specify a retrieval request, where as in relational algebra, we must write a sequence of operations. So it is a procedural language. Database Management Systems Unit 7 Sikkim Manipal University Page No.: 121 Objectives To know about o Tuple Relational Calculus o Domain Relational Calculus Self Assessment Question(s) (SAQs) (for section 7.1) 1. Define Celational Calculus. 7.2 Tuple Relational Calculus The tuple calculus is based on specifying a number of tuple variables. A tuple variable is a variable that 'ranges over' some named relation- that is a variable whose only permitted values are tuples of that relation (that is if tuple variable t ranges over relation R, then at any given time, t represents some individual tuple of R) E.g.: consider that a simple tuple relational calculus query is of the form. {t| COND (t) and t.salary>5000} here t is a tuple variable it ranges over relation employee. Each tuple in a employee relation, that satisfies the condition i.e.salary>5000, will be retrieved. Eg.2: retrive empno, empname and birthdate of employees who are residing at 'Bangalore'. t.empno, t.empname, t.bdate |Employee(t) and t.city='Bangalore'. In this, we first specify the requested attributes and then we specify the condition. Formula Specification of Tuple Relational Calculus: The expressions of the tuple calculus are constructed from the following elements. A general expression of the tuple relational calculus is of the following form. Database Management Systems Unit 7 Sikkim Manipal University Page No.: 122 {t 1 ,A 1 ,t 2 ,A 2 t n |COND(t 1 ,t 2 t n ..t n+m )} where t 1 ,t 2 are tuple variables ranging over some named relation. COND is a formula of the tuple relational calculus, where t.A represents the component of t, where A is an attribute of the relation. Conditions of the form x * y where * is any of the following =, !=, <, >, <=. Well formed Formulas (Wff) A wff is constructed from one or more atoms connected via Boolean operators (AND,OR NOT) and quantifiers( ) according to the rules below. 1. Every atom is a formula. 2. If F 1 and F 2 are formulas, then so are (F 1 and F 2 ), not (F 1 ), and not (F 2 ). The truth values of these four formulas are derived from their component formulas F 1 and F 2 as follows: a) (F 1 and F 2 ) is TRUE is both F 1 , and F 2 are TRUE; otherwise, it is FALSE. b) (F 1 , and F 2 ) is FALSE is both F 1 and F 2 are FALSE; otherwise, it is TRUE. c) Not (F 1 ) is TRUE if F 1 is FALSE; it is FALSE if F 1 is TRUE d) Not (F 2 ) is TRUE if F 2 is FALSE; it is FALSE if F 2 is TRUE. Free and Bound Variables: Each tuple variable within a formula is either free or bound if it is quantified, meaning that it appears in an ( t)or(t) clause, otherwise it is free. The two special symbols called 'quantifiers' that can appear in formulas are the universal quantifier () and the existential quantifiers ( ). If F is a formula, then so is ( t)(F), where t is a tuple variable. The formula ( t)(F) is true if the formula evaluates to true for at least one tuple assigned to free occurrences of t in F; otherwise ( t)(F) is false. Database Management Systems Unit 7 Sikkim Manipal University Page No.: 123 If F is a formula, then so is (t)(F), where t is a tuple variable. The formula (t)(F) is true if the formula evaluates to true for every tuple assigned to free occurrences of t in F; otherwise (t)(F) is false. A tuple variable t in F is bound in a formula F1 of the form. F1 =( t)(F) or F1 =( t)(F) Consider an e.g.: F1=d, Dname='Research' F2=( t)(d.Dnumber=t.Dno) Here tuple variable d is free in both F 1 and F 2 , whereas t is bound to the quantifier in F 2 . The existential quantifier is read 'there exists' Select the employees information who are not from London t.eno, t.Bdate, t.address | employee(e) and NOT (t.city='london') For every project located in 'Bangalore', list the project number the controlling department number, and the department managers last name, address. p.number,p.dnum,m,lname,m.address | project (p) and employee (m) and p.plocation ='Bangalore' and (( d)(department(d)) and p.dnum=d.dnumber and d.mgrssn=m.ssn))) Get the names, department names of all employees whose pay is greater than 10000. e.name, d.name | employee(d) and DEPARTMENT(d) and d.Dno=e.DEPTNO)and {( s)(salary(s)and s.Eno=e.Empno ands.PAY>10000)} The existential quantifier is read 'there exists'. The above e.g. Can be read 'there exist salary tuple with eno value equal to the emp no component of employee relation and pay value greater than 10000. Database Management Systems Unit 7 Sikkim Manipal University Page No.: 124 Consider Px is a tuple variable for relation parts (P). the symbol represents the universal quantifier ("for all"). This formula can therefore be read "for all p tuples the colour is RED". Safe Expressions: A safe expression in relational calculus is one that is guaranteed to yield a finite number of tuples as its result; otherwise, the expression is called unsafe. For example, {t | not(EMPLOYEE(t))} is unsafe because it yields all tuples in the universe that are not employee tuples, which are infinite; such values are not in the domain of the expression. Self Assessment Question(s) (SAQs) (for section 7.2) 1. Define tuple Relational Calculus. 7.3 Domain relational calculus There is another type of relational calculus called domain calculus. The domain calculus differs from the tuple calculus in the type of variables used in formulas. In domain calculus the variables range over single values from domains of attributes rather than ranging over tuples. In other words, domain variables that take on values from an attribute domain rather than values for an entire tuple. An expression of the domain calculus is of the following: eg: {<x1,x2.xn>| COND(x1,x2..xn)} where x1,x2,,,xn represents domain variables. COND is a condition or formula. Expressions of the domain calculus are constructed from the following elements.` Domain variable D,E,F..Each domain variable is constrained to range over some specified domain. Database Management Systems Unit 7 Sikkim Manipal University Page No.: 125 X * Y, here x and y are domain variables. * is one of the comparison operators in the set {=,!=,<,>,<=,>=}and xi and xj are domain variables. Consider R )x1,x2.xi) where R is the name of a relation. This states that a list of values of <x1,x2,,,,xj>, must be a tuple in the relation R, where xi is the value at the it attribute value of the tuple. E.g.: Find the branch name, loan number and amount for loans of over 25000 {<vm Kma>| <b,L,a> borrower ^ b(< b,L,a> loan ^b="Bombay"))) Find the names of all customers who have a loan from the Bombay branch and find the loan amount. { <c,a>| L(< c,L>) borrower ^ b(<b,L,a> loan ^="Bombay"))} Relational Algebra V/S Relational Calculus: 1. Relational algebra is procedural whereas relational calculus is non procedural. 2. Expressive power of relational algebra and relational calculus are equivalent. This means that any query that could be expressed in relational algebra could be expressed by formulas in relational calculus. Self Assessment Question(s) (SAQs) (for Section 7.3) 1. Explain the concept of Domain relational calculus 2. Distinguish between relational Algebra and relational Calculus. 7.4 Summary In this unit we have learnt about tuple and Domain relational calculus. 7.5 Terminal Questions (TQs) 1. Explain briefly the tuple calculus expression. 2. Discuss the well formed formula WFF. 3. Explain briefly the domain calculus expression. Database Management Systems Unit 7 Sikkim Manipal University Page No.: 126 7.6 Multiple Choice Questions (MCQs) 1. is the combination of tuple calculus and domain calculus. (a) Domain (b) Relational calculus (c) Tuple (d) None of the above 2. . .. is procedural. (a) Relational algebra (b) . Relational calculus (c) Tuple (d) None of the above 3. of relational algebra and relational calculus are equivalent. (a) Relational power (b) Expressive Power (c) Tuple (d) None of the above 4. The domain calculus differs from the tuple calculus in the type of variables used in . (a) formulas (b) tables (c) functions (d) None of the above 7.7 Answers to SAQs, TQs, and MCQs 7.7.1 Answers to Self Assessment Question(s) (SAQs) For Section 7.1 1. Relational calculus is the combination of tuple calculus and domain calculus. (Refer section 7.1) Database Management Systems Unit 7 Sikkim Manipal University Page No.: 127 For Section 7.2 1. The tuple calculus is based on specifying a number of tuple variables. (Refer section7.2) For Section 7.3 1. The domain calculus differs from the tuple calculus in the type of variables used in formulas. (Refer section7.3) 2. Relational algebra is procedural whereas relational calculus is non procedural. Expressive power of relational algebra and relational calculus are equivalent. This means that any query that could be expressed in relational algebra could be expressed by formulas in relational calculus. (Refer section 7.3) 7.7.2 Answers to Terminal Questions (TQs) 1. The tuple calculus is based on specifying a number of tuple variables. (Refer section7.2) 2. A Well formed Formulas (Wff) is constructed from one or more atoms connected via Boolean operators (AND,OR NOT) and quantifiers( ) according to the rules mentioned in section 7.2. 3. The domain calculus differs from the tuple calculus in the type of variables used in formulas. In domain calculus the variables range over single values from domains of attributes, rather than ranging over tuples. (Refer section 7.3) 7.7.3 Answers to Multiple Choice Question(s) (MCQs) 1. B 2. A 3. B 4. A