Trc final
Upcoming SlideShare
Loading in...5

Like this? Share it with your network


Trc final






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Trc final Presentation Transcript

  • 2. What is TRC?• it is a calculus that was introduced by Edgar F. Codd as part of the relational model, in order to provide a declarative database-query language for this data model.
  • 3. BASICS
  • 4. Tuple Relational Calculus• It is a nonprocedural query language.• A query is expressed as { t | cond }• Return all tuples T that satisfy the condition Cond.• t is a tuple variable, t[A] denotes the value of tuple t on attribute A
  • 5. Atoms• For the construction of the formula we will assume an infinite set V of tuple variables.• Examples of atoms are:• (t.age = s.age) — t has an age attribute and s has an age attribute with the same value• ( = “priyank”) — tuple t has a name attribute and its value is ”Priyank"• Book(t) — tuple t is present in relation Book.
  • 6. Formulas• Formulas are combined using operators ∧ (and), ∨ (or) and ¬ (not), and we can use the existential quantifier (∃) and the universal quantifier (∀) .• Here ∃ and ∀ quantifier are called bound variable..
  • 7. Predicate Calculus Formula• Set of comparison operatores: <, ≤, >, ≥ , = , ≠• Set of connectives: and ( ^), or (v), not (¬)• Implication (=>): x => y means: if x is true, then y is true.
  • 8. Predicate Calculus Formula (cont’d)• ∃ t ∈ r ( Q(t) ) ≡ There exists a tuple t in relation r such that predicate Q (t) is true• ∀ t ∈ r ( Q(t) ) ≡ Q is true for all tuples t in relation r
  • 9. Formal semantics• " f1 ∧ f2 " is true if and only if " f1 " is true and " f2 " is true,• " f1 ∨ f2 " is true if and only if " f1 " is true or " f2 " is true or both are true,• " ¬ f " is true if and only if " f " is not true,
  • 10. Example• student(rollNo, name, degree, year, sex, deptNo, advisor)• department(deptId, name, hod, phone)Question:Obtain the rollNo, name of all girl students in the Maths Dept (deptNo= 2)
  • 11. • Answer• {s.rollNo,| student(s)^‘F’^ s.deptNo=2}• Here student(s) is true whenever value of s is a tuple in the student relation,• false otherwise
  • 12. Example Relational Schemes• student(rollNo, name, degree, year, sex, deptNo, advisor)• department (deptId, name, hod, phone)• course (courseId, cname, credits, deptNo)• enrollment (rollNo, courseId, sem, year, grade)
  • 13. Example Queries• 1)Determine the departments that do not have any girl students .
  • 14. • student (rollNo, name, degree, year, sex, deptNo, advisor)• department (deptId, name, hod, phone)• Answer is …• {|department(d) ^ ¬(∃s)(student(s) ^‘F’^ s.deptNo= d.deptId)
  • 15. • 2)Obtain the names of courses enrolled by student named Mahesh
  • 16. Answer is …{ | course(c) ^ (∃s) (∃e) ( student(s) ^enrollment(e)^ = “Mahesh”^ s.rollNo=e.rollNo^ c.courseId = e.courseId}
  • 17. • 3)Get the names of students who have taken at least one course taught by their advisor..
  • 18. Output…• { | student(s) ^ (∃e)(∃t)(enrollment(e) ^ teaching(t) ^ e.courseId= t.courseId ^e.rollNo= s.rollNo^ t.empId= s.advisor}
  • 19. • 4) Display the departments whose HODs are teaching at least one course in the current semester.
  • 20. Output• { | department(d) ^(∃t)(teaching(t) ^t.empid= d.hod^ t.sem= ‘odd’^ t.year= ‘2012’)}
  • 21. Safety of Expressions• It is possible to write tuple calculus expressions that generate infinite relations.• For example, expression { t | ¬ t ∈ r } results in an infinite relation if the domain of any attribute of relation r is infinite.
  • 22. To solve this problem• We restrict the set of allowable expressions to safe expressions.• What is safe expression?
  • 23. Definition of Safe Expression• 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 tuple relational formula P.
  • 24. Example• { t | ¬ ( t ∈loan) } is NOT safe. It is possible to have a tuple t not in loan that contains values that do not appear in loan.• All examples in the previous expressions are safe.
  • 25. Limitations of TRC• It can not express queries involving aggregations,closure.• It can not express non-query operations like insert,delete,update.• because those involve modeling the changes in the state of a database.
  • 26. Summary• The relational calculus provides an• alternate way to express queries• • A formal model based on logical formulae and set theory • Equivalence with algebra means can use• either or both – but only one for formal• proofs