SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
TUPLE
RELATIONAL
 CALCULUS
   By RANA MAYUR
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.
BASICS
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
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.
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..
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.
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
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,
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)
• 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
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)
Example Queries
• 1)Determine the departments that
  do not have any girl students .
• 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)
• 2)Obtain the names of courses enrolled
  by student named Mahesh
Answer is …
{c.name | course(c) ^ (∃s) (∃e) ( student(s) ^
enrollment(e)^ s.name = “Mahesh”^ s.rollNo=
e.rollNo^ c.courseId = e.courseId}
• 3)Get the names of students who have taken
  at least one course taught by their advisor..
Output…
• {s.name | student(s) ^ (∃e)(∃t)(enrollment(e)
  ^ teaching(t) ^ e.courseId= t.courseId
  ^e.rollNo= s.rollNo^ t.empId= s.advisor}
• 4) Display the departments whose HODs are
  teaching at least one course in the current
  semester.
Output
• {d.name | department(d) ^(∃t)(teaching(t)
  ^t.empid= d.hod^ t.sem= ‘odd’^ t.year=
  ‘2012’)}
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.
To solve this problem
• We restrict the set of allowable
  expressions to safe expressions.

• What is safe expression?
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.
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.
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.
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

Más contenido relacionado

La actualidad más candente

Sequences 01
Sequences 01Sequences 01
Sequences 01kmfob
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp) Archana432045
 
Differential calculus
Differential calculusDifferential calculus
Differential calculusShubham .
 
5.1 part 1
5.1 part 15.1 part 1
5.1 part 1leblance
 
Chapter 2: Relations
Chapter 2: RelationsChapter 2: Relations
Chapter 2: Relationsnszakir
 
Final relation1 m_tech(cse)
Final relation1 m_tech(cse)Final relation1 m_tech(cse)
Final relation1 m_tech(cse)Himanshu Dua
 
Parametric versus semi nonparametric parametric regression models
Parametric versus semi nonparametric parametric regression modelsParametric versus semi nonparametric parametric regression models
Parametric versus semi nonparametric parametric regression modelsNuriye Sancar
 
13 sequences and series
13   sequences and series13   sequences and series
13 sequences and seriesKathManarang
 
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and orderingBCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and orderingRai University
 

La actualidad más candente (19)

Sequences 01
Sequences 01Sequences 01
Sequences 01
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)
 
Logic DM
Logic DMLogic DM
Logic DM
 
Axioms, postulates
Axioms, postulatesAxioms, postulates
Axioms, postulates
 
Differential calculus
Differential calculusDifferential calculus
Differential calculus
 
5.1[1]
5.1[1]5.1[1]
5.1[1]
 
computational_Maths
computational_Mathscomputational_Maths
computational_Maths
 
5.1 part 1
5.1 part 15.1 part 1
5.1 part 1
 
Linear algebra
Linear algebra Linear algebra
Linear algebra
 
0764141392
07641413920764141392
0764141392
 
Functions O level
Functions   O levelFunctions   O level
Functions O level
 
Chapter 2: Relations
Chapter 2: RelationsChapter 2: Relations
Chapter 2: Relations
 
Introductions to Relations
Introductions to RelationsIntroductions to Relations
Introductions to Relations
 
Final relation1 m_tech(cse)
Final relation1 m_tech(cse)Final relation1 m_tech(cse)
Final relation1 m_tech(cse)
 
Parametric versus semi nonparametric parametric regression models
Parametric versus semi nonparametric parametric regression modelsParametric versus semi nonparametric parametric regression models
Parametric versus semi nonparametric parametric regression models
 
Alg1ch1
Alg1ch1Alg1ch1
Alg1ch1
 
Relations
RelationsRelations
Relations
 
13 sequences and series
13   sequences and series13   sequences and series
13 sequences and series
 
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and orderingBCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
 

Similar a Trc final

Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languagesjamunaashok
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasexabhaysonone0
 
leanCoR: lean Connection-based DL Reasoner
leanCoR: lean Connection-based DL ReasonerleanCoR: lean Connection-based DL Reasoner
leanCoR: lean Connection-based DL ReasonerAdriano Melo
 
Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational CalculusAmiya9439793168
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATELShashi Patel
 
Towards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositoriesTowards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositoriesValentina Paunovic
 
Special webinar on tips for perfect score in sat math
Special webinar on tips for perfect score in sat mathSpecial webinar on tips for perfect score in sat math
Special webinar on tips for perfect score in sat mathCareerGOD
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational modelATS SBGI MIRAJ
 
IRT Unit_ 2.pptx
IRT Unit_ 2.pptxIRT Unit_ 2.pptx
IRT Unit_ 2.pptxthenmozhip8
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational CalculusKunal Anand
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdfGaneshRaghu4
 
Calculas sequence and series
Calculas sequence and seriesCalculas sequence and series
Calculas sequence and seriesVrushang Sangani
 

Similar a Trc final (20)

Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languages
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex
 
leanCoR: lean Connection-based DL Reasoner
leanCoR: lean Connection-based DL ReasonerleanCoR: lean Connection-based DL Reasoner
leanCoR: lean Connection-based DL Reasoner
 
Dbms 14: Relational Calculus
Dbms 14: Relational CalculusDbms 14: Relational Calculus
Dbms 14: Relational Calculus
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
 
Towards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositoriesTowards advanced data retrieval from learning objects repositories
Towards advanced data retrieval from learning objects repositories
 
New part1
New part1New part1
New part1
 
1019Lec1.ppt
1019Lec1.ppt1019Lec1.ppt
1019Lec1.ppt
 
Special webinar on tips for perfect score in sat math
Special webinar on tips for perfect score in sat mathSpecial webinar on tips for perfect score in sat math
Special webinar on tips for perfect score in sat math
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
Stochastic Processes Homework Help
Stochastic Processes Homework Help Stochastic Processes Homework Help
Stochastic Processes Homework Help
 
IRT Unit_ 2.pptx
IRT Unit_ 2.pptxIRT Unit_ 2.pptx
IRT Unit_ 2.pptx
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational Calculus
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
 
Calculas sequence and series
Calculas sequence and seriesCalculas sequence and series
Calculas sequence and series
 
ENG1040 Lec02
ENG1040 Lec02ENG1040 Lec02
ENG1040 Lec02
 
ENG1040 Lec02
ENG1040 Lec02ENG1040 Lec02
ENG1040 Lec02
 
PR7.ppt
PR7.pptPR7.ppt
PR7.ppt
 

Trc final

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