Relational Calculus. Non Procedural or Declarative Calculus has variables, constants, comparison ops, logical connectives and quantifiers. There are TWO.

Slides:



Advertisements
Similar presentations
1.3 Predicates and Quantifiers
Advertisements

B ϋ CHIS MONADIC SECOND ORDER LOGIC Verification Seminar V.Sowjanya Lakshmi ( Subhasree M.
Relational Algebra Chapter 4, Part A
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
The Relational Calculus
Relational Calculus   Logic, like whiskey, loses its beneficial effect when taken in too large quantities. --Lord Dunsany.
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
1 TRC vs DRC 한욱신. 2 Queries in TRC and DRC  TRC Q = {t| f(t)} where t is a (free) tuple variable and f(t) is a well-formed formula  DRC.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Relational Algebra Content based on Chapter 4 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
R ELATIONAL A LGEBRA M ORE POINTERS FROM T UESDAY.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
1 Lecture 5: Relational calculus
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.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
1 SQL: Structured Query Language Chapter 5. 2 SQL and Relational Calculus relationalcalculusAlthough relational algebra is useful in the analysis of query.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Calculus R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion. Ronald Graham Elements of Ramsey.
Introduction to Database Systems 1 Relational Calculus Relational Model : Topic 2.
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.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
The Relational Model: Relational Calculus
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
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.
Database Management Systems,1 Relational Calculus.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 14 A First Course in Database Systems.
Relational Calculus R&G, Chapter 4. Relational Calculus Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). Calculus.
Relational Calculus CS 186, Spring 2005, Lecture 9 R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion.
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)
IST 210 The Relational Language Todd S. Bacastow January 2004.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
1 Copyright © Kyu-Young Whang Relational Calculus Chapter 4, Part B.
1 Databases II (Fall 2009) Professor: Iluju Kiringa SITE 5072.
Copyright © Curt Hill The Relational Calculus Another way to do queries.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Relational Calculus Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Relational Calculus. Relational calculus query specifies what is to be retrieved rather than how to retrieve it. – No description of how to evaluate a.
CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
Jun-Ki Min.  Based on predicate calculus ◦ Predicate  a function whose value is true or false  non-procedural ◦ A relational calculus expression creates.
1 Relational Algebra. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational model supports.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
A First Course in Database Systems
Relational Calculus Chapter 4, Part B
Chapter 6: Formal Relational Query Languages
The Relational Algebra and Relational Calculus
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Relational Calculus.
Chapter 6: Formal Relational Query Languages
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
Chapter 6: Formal Relational Query Languages
CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth
Relational Algebra & Calculus
Chapter 27: Formal-Relational Query Languages
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Calculus Chapter 4 – Part II.
Relational Calculus Chapter 4, Part B
CS 405G: Introduction to Database Systems
Presentation transcript:

Relational Calculus

Non Procedural or Declarative Calculus has variables, constants, comparison ops, logical connectives and quantifiers. There are TWO VARIANTS of Relational Calculus TUPLE RELATIONAL CALCULUS (TRC) Variables range over (i.e., get bound to) tuples DOMAIN RELATIONAL CALCULUS (DRC) Variables range over domain elements (field/attribute values) Both TRC and DRC are simple subsets of first-order logic Expressions in the calculus are called formulas. An answer tuple is essentially an assignment of constants to variables that make the formula evaluate to true.

Syntax of TRC Queries Query: {T|P(T)} T is tuple variable P(T) is a formula that describes T Syntax Rel : Relation Name R, S : - Tuple Variables a : Attribute of R b : - Attribute of S op : Operator in the set {,=, ≤, ≥, ≠ } Atomic formula R ∈ Rel R.a op S.b, op is one of {,=, ≤, ≥, ≠ } R.a op constant Formula (Boolean condition) Made up of one or more atoms connected via logical operators ∧, ∨, and ¬

Quantifiers Existential quantifier ( ∃ ): x ∃ (f(x)) for formula f with free variable x Is true if there is some tuple which when substituted for x makes f true Universal quantifier ( ∀ ): ∀ x (f(x)) for formula f with free variable x Is true if any tuple substituted for x makes f true i.e. all tuples when substituted for x make f true

Semantics of TRC Queries Free variables in a formula take on the values of tuples A tuple is in the defined relation if and only if when substituted for a free variable, it satisfies (makes true) the formula Bound variable: ∀ x, ∃ x bind x – truth or falsehood no longer depends on a specific value of x Free variables: If x is not bound it is free. A variable is said to be FREE in a formula/subformula, if the (sub)formula does not contain an occurrence of a quantifier that binds it.

Example Relational Scheme Schemestudent (rollNo, name, degree, year, sex, deptNo, advisor) Department (deptId, name, hod, phone) professor (empId, name, sex, startYear, deptNo, phone) course (courseId, cname, credits, deptNo) enrollment (rollNo, courseId, sem, year, grade) teaching (empId, courseId, sem, year, classRoom) preRequisite(preReqCourse, courseID)

Example TRC queries Obtain the rollNo, name of all girl students in the Maths Dept {s.rollNo,s.name | student(s) ∧ s.sex=‘F’ ∧ ( ∃ d)(department(d) ∧ d.name=‘Maths’ ∧ d.deptId= s.deptNo)} s: free tuple variable d: existentially bound tuple variable Existentially or universally quantified tuple variables can be used on the RHS of the vertical bar to specify query conditions Attributes of free (or unbound ) tuple variables can be used on LHS of vertical bar to specify attributes required in the results

Example queries in TRC Determine the departments that do not have any girl students student (rollNo, name, degree, year, sex, deptNo, advisor) department (deptId, name, hod, phone) {d.name | department(d) ∧ ¬( ∃ s)(student(s) ∧ s.sex=‘F’ ∧ s.deptNo= d.deptId)

Example queries in TRC Obtain the names of courses enrolled by student named Mahesh {c.name | course(c) ∧ ( ∃ s) ( ∃ e) ( student(s) ∧ enrollment(e) ∧ s.name = “Mahesh” ∧ s.rollNo = e.rollNo ∧ c.courseId = e.courseId}

Example queries in TRC Get the names of students who have scored ‘S’ in all subjects they have enrolled. Assume that every student is enrolled in at least one course. {s.name | student(s) ∧ ( ∀ e)(( enrollment(e) ∧ e.rollNo = s.rollNo) → e.grade =‘S’)} person P with all S grades: for enrollment tuples not having her roll number, LHS is false for enrollment tuples having her roll number, LHS is true, RHS also true so the implication is true for all e tuples person Q with some non-S grades: for enrollment tuples not having her roll number, LHS is false for enrollment tuples having her roll number, LHS is true, but RHS is false for at least one tuple. So the implication is not true for at least one tuple.

Example queries in TRC Get the names of students who have taken at least one course taught by their advisor {s.name | student(s) ∧ ( ∃ e)( ∃ t)(enrollment(e) ∧ teaching(t) ∧ e.courseId= t.courseId ∧ e.rollNo= s.rollNo ∧ t.empId= s.advisor} Display the departments whose HODs are teaching at least one course in the current semester {d.name | department(d) ∧ ( ∃ t)(teaching(t) ∧ t.empid = d.hod ∧ t.sem= ‘odd’ ∧ t.year = ‘2008’)}

Domain Relational Calculus Domain Variable: A variable that ranges over the values in the domain of some attribute. DRC Query: xi - Domain variable or constant - a DRC formula The ONLY free variables in the formula are the variables among the xi, 1 ≤ i ≤ n. The result of the query is the set of all tuples a DRC formula for which the formula evaluates to true.

Example Sailors(sid:integer, sname:string, rating:integer, age:real) Boats(bid:integer, bname:string, color:string) Reserves(sid:integer, bid:integer, day:date) Find all sailors with a rating above 7 {(I, N, T, A) | (I, N, T, A) ∈ Sailors ∧ T > 7} Find the names of sailors who have reserved boat 103 {(N) | ∃ I, T, A((I, N, T, A) ∈ Sailors ∧ ∃ Ir, Br,D((Ir, Br,D) ∈ Reserves ∧ Ir = I ∧ Br = 103))}

Example Find the names of sailors who have reserved at least two boats {(N) | ∃ I, T, A((I, N, T, A) ∈ Sailors ∧ ∃ Br1, Br2,D1,D2 ((I, Br1,D1) ∈ Reserves ∧ (I, Br2,D2) ∈ Reserves ∧ Br1 ≠ Br2))} Find the names of sailors who have reserved all the boats {(N) | ∃ I, T, A((I, N, T, A) ∈ Sailors ∧ ∀( B, BN, C) ∈ Boats ( ∃( Ir, Br,D) ∈ Reserves (I = Ir ∧ Br = B)))} Find sailors who have reserved all red boats {(I, N, T, A) | (I, N, T, A) ∈ Sailors ∧ ∀( B, BN, C) ∈ Boats (C = ‘red’ → ∃ (Ir, Br, D) ∈ Reserves(I = Ir ∧ Br = B))}