1 Minggu 3, Pertemuan 6 Relational Calculus Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
Advertisements

The Relational Calculus
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
CSC271 Database Systems Lecture # 13. Summary: Previous Lecture  Grouping through GROUP BY clause  Restricted groupings  Subqueries  Multi-Table queries.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
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.
1 Minggu 4, Pertemuan 8 SQL: Data Manipulation (Cont.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Lesson II The Relational Model © Pearson Education Limited 1995, 2005.
Relational Calculus. Another Theoretical QL-Relational Calculus n Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus.
1 Minggu 1, Pertemuan 1 Introduction to Database Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Minggu 3, Pertemuan 5 Relational Algebra (Cont.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Chapter 5 Relational Algebra and Relational Calculus.
1 Minggu 11, Pertemuan 22 Conceptual Database Design (Chapter 14.1, 3rd ed.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
1 Pertemuan 10 The Manipulative part of the object data model (Lanjutan bagian 1) Matakuliah: M0174/OBJECT ORIENTED DATABASE Tahun: 2005 Versi: 1/0.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Chapter 6 SQL: Data Manipulation Cont’d. 2 ANY and ALL u ANY and ALL used with subqueries that produce single column of numbers u ALL –Condition only.
1 Pertemuan 8 The Object Definition Language (Lanjutan) Matakuliah: M0174/OBJECT ORIENTED DATABASE Tahun: 2005 Versi: 1/0.
Relational Algebra & Relational Calculus Dale-Marie Wilson, Ph.D.
Rutgers University Relational Calculus 198:541 Rutgers University.
Relational Algebra.  Introduction  Relational Algebra Operations  Projection and Selection  Set Operations  Joins  Division  Tuple Relational Calculus.
Lecture 3 [Self Study] Relational Calculus
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
1 CS 430 Database Theory Winter 2005 Lecture 6: Relational Calculus.
CSC271 Database Systems Lecture # 12. Summary: Previous Lecture  Row selection using WHERE clause  WHERE clause and search conditions  Sorting results.
Relational Algebra Chapter 4 CIS 458 Sungchul Hong.
Chapter 4 Relational Algebra & Relational Calculus.
CSC271 Database Systems Lecture # 9. Summary: Previous Lecture  Cartesian product  Join  Theta join, equijoin, natural join  Outer join (left, right,
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
Chapter 6 SQL: Data Manipulation (Advanced Commands) Pearson Education © 2009.
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.
C HAPTER 4 Relational Algebra and Relational Calculus Transparencies © Pearson Education Limited 1995,
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Lecture#6: Relational calculus.
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
The Relational Calculus (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Copyright © 2004 Ramez Elmasri and Shamkant Navathe The Relational Calculus The main reference of this presentation is the textbook and PPT from : Elmasri.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 5: Other Relational Languages.
1 Copyright © Kyu-Young Whang Relational Calculus Chapter 4, Part B.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational tuple calculus.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2014.
1 Minggu 6, Pertemuan 12 Query Processing Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
LECTURE THREE RELATIONAL ALGEBRA 11. Objectives  Meaning of the term relational completeness.  How to form queries in relational algebra. 22Relational.
Relational Calculus. Relational calculus query specifies what is to be retrieved rather than how to retrieve it. – No description of how to evaluate a.
Teacher Workshop Database Design Pearson Education © 2014.
Chapter 11 SQL: Data Manipulation
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Calculus Chapter 4, Section 4.3.
Tahun : <<2007>> Versi : <<2/1>>
Database Applications (15-415) Relational Calculus Lecture 6, September 6, 2016 Mohammad Hammoud.
Chapter Name SQL: Data Manipulation
DATABASE SYSTEM.
Relational Algebra and Relational Calculus
Relational Calculus Chapter 4, Part B 7/1/2019.
Relational Calculus Chapter 4, Part B
Presentation transcript:

1 Minggu 3, Pertemuan 6 Relational Calculus Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0

2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa dapat menjelaskan konsep relational calculus (C2)

3 Outline Materi How to form queries in tuple relational calculus. How to form queries in domain relational calculus. Categories of relational DML.

4 Relational Calculus Relational calculus query specifies what is to be retrieved rather than how to retrieve it. –No description of how to evaluate a query. In first-order logic (or predicate calculus), predicate is a truth-valued function with arguments. When we substitute values for the arguments, function yields an expression, called a proposition, which can be either true or false.

5 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.

6 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: i.e., variable whose only permitted values are tuples of the relation. Specify range of a tuple variable S as the Staff relation as: Staff(S) To find set of all tuples S such that P(S) is true:{S | P(S)}

7 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}

8 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.

9 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 with same branchNo as the branchNo of the current Staff tuple, S, and is located in London’.

10 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’.

11 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.

12 Example - Tuple Relational Calculus 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’)}

13 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)))}

14 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’))}

15 Tuple Relational Calculus Expressions can generate an infinite set. For example: {S | ~Staff(S)} To avoid this, add restriction that all values in result must be values in the domain of the expression.

16 Domain Relational Calculus Uses variables that take values from domains instead of tuples of relations. If F(d 1, d 2,..., d n ) stands for a formula composed of atoms and d 1, d 2,..., d n represent domain variables, then: {d 1, d 2,..., d n | F(d 1, d 2,..., d n )} is a general domain relational calculus expression.

17 Example - Domain Relational Calculus a)Find the names of all managers who earn more than £25,000. {fN, lN | (  sN, posn, sex, DOB, sal, bN) (Staff (sN, fN, lN, posn, sex, DOB, sal, bN)  posn = ‘Manager’  sal > 25000)}

18 Example - Domain Relational Calculus b)List the staff who manage properties for rent in Glasgow. {sN, fN, lN, posn, sex, DOB, sal, bN | (  sN1,cty)(Staff(sN,fN,lN,posn,sex,DOB,sal,bN)  PropertyForRent(pN, st, cty, pc, typ, rms, rnt, oN, sN1, bN1)   (sN=sN1)  cty=‘Glasgow’)}

19 Example - Domain Relational Calculus c)List the names of staff who currently do not manage any properties for rent. {fN, lN | (  sN) (Staff(sN,fN,lN,posn,sex,DOB,sal,bN)  ( ~ (  sN1) (PropertyForRent(pN, st, cty, pc, typ, rms, rnt, oN, sN1, bN1)  (sN=sN1))))}

20 Example - Domain Relational Calculus d)List the names of clients who have viewed a property for rent in Glasgow. {fN, lN | (  cN, cN1, pN, pN1, cty) (Client(cN, fN, lN,tel, pT, mR)  Viewing(cN1, pN1, dt, cmt)  PropertyForRent(pN, st, cty, pc, typ, rms, rnt,oN, sN, bN)  (cN = cN1)  (pN = pN1)  cty = ‘Glasgow’)}

21 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.

22 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).

23 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.