Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

No Downloads

Total views

789

On SlideShare

0

From Embeds

0

Number of Embeds

2

Shares

0

Downloads

25

Comments

0

Likes

1

No embeds

No notes for slide

- 1. TUPLERELATIONAL CALCULUS By RANA MAYUR
- 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• (t.name = “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,s.name| student(s)^ s.sex=‘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 …• {d.name|department(d) ^ ¬(∃s)(student(s) ^ s.sex=‘F’^ s.deptNo= d.deptId)
- 15. • 2)Obtain the names of courses enrolled by student named Mahesh
- 16. Answer is …{c.name | course(c) ^ (∃s) (∃e) ( student(s) ^enrollment(e)^ s.name = “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…• {s.name | 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• {d.name | 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

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment