Relational Calculus

Relational Calculus

RELATIONAL CALCULUS • Relational Algebra is a PROCEDURAL LANGUAGE => we must explicitly provide a sequence of operations to generate a desired output result • Relational Calculus is a DECLARATIVE LANGUAGE => we specify what to retrieve, not how to retrieve it Declarative ~ Non-Procedural • TUPLE Relational Calculus Two variants of Domain Relational Calculus relational calculus st Both based on 1 order predicate calculus RELATIONAL CALCULUS If a retrieval can be specified in the relational calculus, it can be specified in the relational algebra, and vise versa →expressive power of the languages is identical A query language L is Relationally complete if L can express any query that can be expressed in the relational calculus OPERATIONS in Tuple Relational Calculus ∧ - AND General power of ∨ - OR 1st order predicate calculus – allow ¬ - NOT more flexible ∃x – there exists x expression formats ∀x – for all x TUPLE RELATIONAL CALCULUS A query Predicate in the → { t| P(t) } T.R.C Set of all tuples such that P(t) is true for t Example: (∧) t.salary Employee.salary > 5000 {t | t ∈ Employee and t[SALARY] > 5000 Operator or single Boolean test that tuple Arrtibute of t tuple only t is a member of the employee realtion Standard conditional operation =>similar in function to SELECT(σ) T ← σ salary> 5000 (EMPLOYEE) condition relation TUPLE RELATIONAL CALCULUS Handling Projections (Π) Projection {t| э e € EMPLOYEE (t[LNAME] = e[LNAME]^e[SALARY] >5000 There exists Select condition (equiv to : ΠLNAME ( σ SALARY> 5000 (EMPLOYEE)) The new relation t is only defined for the attributes it is explicitly assigned (eg LNAME) JOINS IN THE TUPLE RELATIONAL CALCULUS projection {t | э d € DEPARTMENT (t[DNAME] = d[DNAME] projection ^ э e € EMPLOYEE (t[LNAME] = e[LNAME] ^ d[MGRSSN] = e[SSN] )) Join condition ~ Π DNAME,LNAME (DEPARTMENT MGRSSN=SSN (DNO=DNUMBER)EMPLOYEE Another join option GENERAL FORMAT OF THE TUPLE RELATIONAL CALCULUS { t | э d € DEPARTMENT (t[DNAME] = d[DNAME] Project and rename Result relation t ^t[DNO] = d[DNUMBER] (only has attributes : explicitly defined) Selection (σ) on ^d[DNUMBER] <3 DEPARTMENT : ^э e € EMPLOYEE( t[LNAME] = e[LNAME] Project and rename ^t[FNAME] = e[FNAME] ^ : ^ e[SEX] = M Selection (σ) conditions on ^ e[SALARY] <50000 EMPLOYEE : ^ d[MGRSSN] = e[SSN] )) } Join condition GENERAL FORMAT OF THE TUPLE RELATIONAL CALCULUS { t | э d € DEPARTMENT ( Existentialize Relations э e € EMPLOYEE ( d[DNUMBER] <3 Selection (σ) on ^ e[SEX] = M DEPARTMENT ^ e[SALARY] <50000 And EMPLOYEE ^ d[MGRSSN] = e[SSN] Join Condition(s) ^ t[DNO] = d[DNUMBER] ^ t[DNAME] = d[DNAME] ^ t[LNAME] = e[LNAME] Projection ^t[FNAME] = e[FNAME] )) } DOMAIN RELATIONAL CALCULUS Can represent/constraint domain/attribute values more directly TRC:{t | t € EMPLOYEE ^t[SALARY] >50000} DRC :{<f,l,s> | < f,l,s,b,a> € EMPLOYEE ^ S>50000} The “domain” Attributes listed An attribute of values satisfying explicitly <…> the following conditions DRC : { <l> | <f,l,s,b,a> € EMPLOYEE ^ S>50000} Projecting domain value for last name .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us