Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model III (based on notes by Silberchatz,Korth, and.

Slides:



Advertisements
Similar presentations
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Advertisements

Relational Calculus and Datalog
Chapter 3 Tuple and Domain Relational Calculus. Tuple Relational Calculus.
Ver 1,12/09/2012Kode :CCs 111,Sistem basis DataFASILKOM Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. ©Silberschatz, Korth and.
RELATIONAL CALCULUS Rohit Khokher. INTRODUCTION Relational calculus is a formal query language where the queries are expressed as variables and formulas.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
Relational Calculus Ameetinder Singh CS 157A. Tuple Relational Calculus  non-procedural query language as compared to relational algebra that is procedural.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
SQL Structured Query Language Meizhen Huang. Content (4.1 – 4.4) Background Parts of SQL Basic Structure Set Operations Aggregate Functions.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
©Silberschatz, Korth and Sudarshan1Database System Concepts Tuple and Domain Calculus Tuple Relational Calculus Domain Relational Calculus.
Relational Algebra. Relational Query Languages n Query = “retrieval program” n Language examples: ù Theoretical : 1. Relational Algebra 2. Relational.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Calculus Objectives  Tuple Calculus  Domain Calculus  QBE & SQL  Related Examples.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model – SQL Part I (based on notes by Silberchatz,Korth,
Chapters 2 & 6 The Relational Model. 2  A tabular data structure  Tables (relations) with unique names  rows (tuples/entities/records)  columns (attributes/fields)
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Banking Example  branch (branch-name, branch-city, assets)  customer (customer-name, customer-street,
Chapter 5: Other Relational Languages. 5.2 Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus Query-by-Example.
Relational Model: Examples. Banking Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account.
Relational Algebra Instructor: Mohamed Eltabakh 1.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model – SQL Part II (based on notes by Silberchatz,Korth,
Department of Computer Science, HKUST 1 Comp 231 Database Management Systems Comp 231 Database Management Systems 3. Relational Data Model.
Computing & Information Sciences Kansas State University Tuesday, 13 Feb 2007CIS 560: Database System Concepts Lecture 12 of 42 Tuesday, 13 February 2007.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Lecture#6: Relational calculus.
CS 370 Database Systems Lecture 11 Relational Algebra.
Computing & Information Sciences Kansas State University Thursday, 08 Feb 2007CIS 560: Database System Concepts Lecture 11 of 42 Thursday, 08 February.
Midterm 2 Revision Prof. Sin-Min Lee Department of Mathematics and Computer Science San Jose State University.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
ICOM 5016 – Introduction to Database Systems Lecture 8 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 5 Other Relational Languages.
Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational model.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model I (based on notes by Silberchatz,Korth, and Sudarshan.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational domain calculus.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 – DB Applications C. Faloutsos & A. Pavlo Lecture#5: Relational calculus.
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.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Computing & Information Sciences Kansas State University Wednesday, 17 Sep 2008CIS 560: Database System Concepts Lecture 9 of 42 Wednesday, 18 September.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 5: Other Relational Languages.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
1 Session 3 Welcome: To session 3-the fourth learning sequence “Relational algebra “ Recap : In the previous learning sequences, we discussed the four.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational tuple calculus.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Temple University – CIS Dept. CIS616– Principles of Database Systems V. Megalooikonomou Relational Model (based on notes by Silberchatz,Korth, and Sudarshan.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
CS 480: Database Systems Lecture 16 February 20,2013.
Temple University – CIS Dept. CIS661– Principles of Database Systems
Chapter 6: Formal Relational Query Languages
Lecture #4: Relational Algebra
Database Applications (15-415) Relational Calculus Lecture 6, September 6, 2016 Mohammad Hammoud.
Lecture#5: Relational calculus
Chapter 5: Other Relational Languages
Instructor: Mohamed Eltabakh
Chapter 6: Formal Relational Query Languages
Chapter 27: Formal-Relational Query Languages
Presentation transcript:

Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model III (based on notes by Silberchatz,Korth, and Sudarshan and notes by C. Faloutsos at CMU)

Overview history concepts Formal query languages relational algebra rel. tuple calculus rel. domain calculus

General Overview - rel. model history concepts Formal query languages relational algebra rel. tuple calculus rel. domain calculus

Overview - detailed rel. tuple calculus why? details examples equivalence with rel. algebra more examples; ‘safety’ of expressions rel. domain calculus + QBE

Safety of expressions FORBIDDEN: It has infinite output!! Instead, always use

Safety of expressions Possible to write tuple calculus expressions that generate infinite relations, e.g., {t |  t  r } results in an infinite relation if the domain of any attribute of relation r is infinite To guard against the problem, we restrict the set of allowable expressions to safe expressions. An expression {t | P (t) } in the tuple relational calculus is safe if every component of t appears in one of the relations, tuples, or constants that appear in P

More examples: Banking example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city) account (account-number, branch-name, balance) loan (loan-number, branch-name, amount) depositor (customer-name, account-number) borrower (customer-name, loan-number)

Example Queries Find the loan-number, branch-name, and amount for loans of over $1200 {t | t  loan  t [amount]  1200} Find the loan number for each loan of an amount greater than $1200 {t |  s  loan (t [loan-number] = s [loan-number]  s [amount]  1200} Notice that a relation on schema [loan-number] is implicitly defined by the query

Example Queries Find the names of all customers having a loan, an account, or both at the bank {t |  s  borrower(t[customer-name] = s[customer-name])   u  depositor(t[customer-name] = u[customer- name]) Find the names of all customers who have a loan and an account at the bank {t |  s  borrower(t[customer-name] = s[customer-name])   u  depositor(t[customer-name] = u[customer- name])

Example Queries Find the names of all customers having a loan at the Perryridge branch {t |  s  borrower(t[customer-name] = s[customer-name]   u  loan(u[branch-name] = “Perryridge”  u[loan-number] = s[loan-number]))} Find the names of all customers who have a loan at the Perryridge branch, but no account at any branch of the bank {t |  s  borrower(t[customer-name] = s[customer-name]   u  loan(u[branch-name] = “Perryridge”  u[loan-number] = s[loan-number]))  not  v  depositor (v[customer-name] = t[customer-name]) }

Example Queries Find the names of all customers having a loan from the Perryridge branch, and the cities they live in {t |  s  loan(s[branch-name] = “Perryridge”   u  borrower (u[loan-number] = s[loan-number]  t [customer-name] = u[customer-name])   v  customer (u[customer-name] = v[customer-name]  t[customer-city] = v[customer-city])))}

Example Queries Find the names of all customers who have an account at all branches located in Brooklyn: {t |  c  customer (t[customer.name] = c[customer-name])   s  branch(s[branch-city] = “Brooklyn”   u  account ( s[branch-name] = u[branch-name]   s  depositor ( t[customer-name] = s[customer-name]  s[account-number] = u[account-number] )) )}

General Overview relational model Formal query languages relational algebra rel. tuple calculus rel. domain calculus

Overview - detailed rel. tuple calculus dfn details equivalence to rel. algebra rel. domain calculus + QBE

Rel. domain calculus (RDC) Q: why? A: slightly easier than RTC, although equivalent - basis for QBE idea: domain variables (w/ F.O.L.) – e.g.: ‘find STUDENT record with ssn=123’

Rel. Dom. Calculus find STUDENT record with ssn=123’

Details Like R.T.C - symbols allowed: quantifiers

Details but: domain (= column) variables, as opposed to tuple variables, e.g.: ssn name address

Domain Relational Calculus A nonprocedural query language equivalent in power to the tuple relational calculus Each query is an expression of the form: {  x 1, x 2, …, x n  | P (x 1, x 2, …, x n )} x 1, x 2, …, x n represent domain variables P represents a formula similar to that of the predicate calculus

Example queries Find the branch-name, loan-number, and amount for loans of over $1200 {  l, b, a  |  l, b, a   loan  a > 1200} Find the names of all customers who have a loan of over $1200 {  c  |  l, b, a (  c, l   borrower   l, b, a   loan  a > 1200)} Find the names of all customers who have a loan from the Perryridge branch and the loan amount: {  c, a  |  l (  c, l   borrower   b(  l, b, a   loan  b = “Perryridge”))} or {  c, a  |  l (  c, l   borrower   l, “Perryridge”, a   loan)}

Example Queries Find the names of all customers having a loan, an account, or both at the Perryridge branch: {  c  |  l ({  c, l   borrower   b,a (  l, b, a   loan  b = “Perryridge”))   a (  c, a   depositor   b,n (  a, b, n   account  b = “Perryridge”))} Find the names of all customers who have an account at all branches located in Brooklyn: {  c  |  n (  c, s, n   customer)   x,y,z (  x, y, z   branch  y = “Brooklyn”)   a,b (  x, y, z   account   c,a   depositor)}

Reminder: our Mini-U db CLASS c-idc-nameunits cis331d.b.2 cis321o.s.2 TAKES SSNc-idgrade 123cis331A 234cis331B

Examples find all student records RTC:

Examples (selection) find student record with ssn=123

Examples (selection) find student record with ssn=123 RTC: or

Examples (projection) find name of student with ssn=123

Examples (projection) find name of student with ssn=123 need to ‘restrict’ “a” RTC:

Examples (projection) find name of student with ssn=123 - RTC:

Examples cont’d (union) get records of both PT and FT students RTC:

Examples cont’d (union) get records of both PT and FT students

Examples difference: find students that are not staff RTC:

Examples difference: find students that are not staff

Cartesian product eg., dog-breeding: MALE x FEMALE gives all possible couples x =

Cartesian product find all the pairs of (male, female) - RTC:

Cartesian product find all the pairs of (male, female) - RDC:

‘Proof’ of equivalence rel. algebra rel. domain calculus rel. tuple calculus

Overview - detailed rel. domain calculus why? details examples equivalence with rel. algebra more examples; ‘safety’ of expressions

More examples join: find names of students taking cis351

Reminder: our Mini-U db

More examples join: find names of students taking cis351 - in RTC

More examples join: find names of students taking cis351 - in RDC

Sneak preview of QBE: TAKES SSNc-idgrade _xcis351

Sneak preview of QBE: TAKES SSNc-idgrade _xcis351 very user friendly heavily based on RDC very similar to MS Access interface

More examples 3-way join: find names of students taking a 2-unit course - in RTC: selection projection join

Reminder: our Mini-U db CLASS c-idc-nameunits cis331d.b.2 cis321o.s.2 grade TAKES SSNc-id 123cis331A 234cis331B _x.P _x_y 2

More examples 3-way join: find names of students taking a 2-unit course

More examples 3-way join: find names of students taking a 2-unit course

Even more examples: self -joins: find Tom’s grandparent(s)

Even more examples: self -joins: find Tom’s grandparent(s)

Even more examples: self -joins: find Tom’s grandparent(s)

Even more examples: self -joins: find Tom’s grandparent(s)

Hard examples: DIVISION find suppliers that shipped all the ABOMB parts

Hard examples: DIVISION find suppliers that shipped all the ABOMB parts

Hard examples: DIVISION find suppliers that shipped all the ABOMB parts

More on division find students that take all the courses that ssn=123 does (and maybe even more)

More on division find students that take all the courses that ssn=123 does (and maybe even more)

Safety of expressions similar to RTC FORBIDDEN:

Safety of Expressions {  x 1, x 2, …, x n  | P(x 1, x 2, …, x n )} is safe if all of the following hold: 1. All values that appear in tuples of the expression are values from dom a(P) (that is, the values appear either in P or in a tuple of a relation mentioned in P ) 2.For every “there exists” subformula of the form  x (P 1 (x)), the subformula is true if and only if there is a value x in dom (P 1 ) such that P 1 (x) is true. 3. For every “for all” subformula of the form  x (P 1 (x)), the subformula is true if and only if P 1 (x) is true for all values x from dom (P 1 ).

Overview - detailed rel. domain calculus + QBE dfn details equivalence to rel. algebra

table