SlideShare a Scribd company logo
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
1
Tuple Relational Calculus ( TRC )
Introduction
Procedural Query language
query specification involves giving a step by step process of
obtaining the query result
e.g., relational algebra
usage calls for detailed knowledge of the operators involved
difficult for the use of non-experts
Declarative Query language
query specification involves giving the logical conditions the
results are required to satisfy
easy for the use of non-experts
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
2
TRC – a declarative query language
Tuple variable – associated with a relation
( called the range relation )
• takes tuples from the range relation as its values
• t: tuple variable over relation r with scheme R(A,B,C )
t.A stands for value of column A etc
TRC Query – basic form:
{ t1.Ai1
, t2.Ai2
,…tm.Aim
| θ }
predicate calculus expression
involving tuple variables
t1, t2,…, tm, tm+1,…,ts
- specifies the condition to be satisfied
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
3
An example TRC query
student (rollNo, name, degree, year, sex, deptNo, advisor )
department (deptId, name, hod, phone )
Obtain the rollNo, name of all girl students
in the Maths Dept (deptId = 2)
{s.rollNo,s.name| student(s)^ s.sex=‘F’^ s.deptNo=2}
attributes
required in
the result
This predicate is true whenever
value of s is a tuple from the
student relation, false otherwise
In general, if t is a tuple variable with range
relation r, r( t ) is taken as a predicate which
is true if and only if the value of t is a tuple in r
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
4
Atomic expressions are the following:
1. r ( t ) -- true if t is a tuple in the relation instance r
2. t1. Ai <compOp> t2 .Aj compOp is one of {<, ≤ , >, ≥, =, ≠ }
3. t.Ai <compOp> c c is a constant of appropriate type
Composite expressions:
1. Any atomic expression
2. F1 ∧ F2 ,, F1 ∨ F2 , ¬ F1 where F1 and F2 are expressions
3. (∀t) (F), (∃t) (F) where F is an expression
and t is a tuple variable
Free Variables
Bound Variables – quantified variables
General form of the condition in TRC queries
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
5
All possible tuple assignments to the free variables in the query are
considered.
For any specific assignment,
if the expression to the right of the vertical bar evaluates to true,
that combination of tuple values
would be used to produce a tuple in the result relation.
While producing the result tuple, the values of the attributes for the
corresponding tuple variables as specified on the left side of the
vertical bar would be used.
Note: The only free variables are the ones that appear to the left
of the vertical bar
Interpretation of the query in TRC
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
6
Obtain the rollNo, name of all girl students in the
Maths Dept
{s.rollNo,s.name | student(s) ^ s.sex=‘F’ ^
(∃ d)(department(d) ^ d.name=‘Maths’
^ d.deptId = s.deptNo)}
s: free tuple variable d: existentially bound tuple variable
Existentially or universally quantified tuple variables can be used
on the RHS of the vertical bar to specify query conditions
Attributes of free (or unbound ) tuple variables can be used on LHS
of vertical bar to specify attributes required in the results
Example TRC queries
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
7
Example Relational Scheme
student (rollNo, name, degree, year, sex, deptNo, advisor)
department (deptId, name, hod, phone)
professor (empId, name, sex, startYear, deptNo, phone)
course (courseId, cname, credits, deptNo)
enrollment (rollNo, courseId, sem, year, grade)
teaching (empId, courseId, sem, year, classRoom)
preRequisite (preReqCourse, courseID)
Q2
Q3
Q4
Q5
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
8
Example queries in TRC (1/5)
1)Determine the departments that do not have
any girl students
student (rollNo, name, degree, year, sex, deptNo, advisor)
department (deptId, name, hod, phone)
{d.name|department(d) ^
¬(∃ s)(student(s) ^
s.sex =‘F’ ^ s.deptNo = d.deptId)
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
9
2)Obtain the names of courses enrolled by student
named Mahesh
{c.name | course(c) ^
(∃s) (∃e) ( student(s) ^ enrollment(e)
^ s.name = “Mahesh”
^ s.rollNo = e.rollNo
^ c.courseId = e.courseId }
Examples queries in TRC (2/5) Schema
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
10
3)Get the names of students who have scored ‘S’ in all
subjects they have enrolled. Assume that every
student is enrolled in at least one course.
{s.name | student(s) ^
(∀e)(( enrollment(e) ^
e.rollNo = s.rollNo) → e.grade =‘S’)}
person P with all S grades:
for enrollment tuples not having her roll number, LHS is false
for enrollment tuples having her roll number, LHS is true, RHS also true
so the implication is true for all e tuples
person Q with some non-S grades:
for enrollment tuples not having her roll number, LHS is false
for enrollment tuples having her roll number, LHS is true, but RHS is false for
at least one tuple.
So the implication is not true for at least one tuple.
Examples queries in TRC (3/5) Schema
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
11
4) Get the names of students who have taken at least
one course taught by their advisor
{s.name | student(s) ^
(∃e)(∃t)(enrollment(e) ^ teaching(t) ^
e.courseId = t.courseId ^
e.rollNo = s.rollNo ^
t.empId = s.advisor}
5) Display the departments whose HODs are teaching
at least one course in the current semester
{d.name | department(d) ^(∃t)(teaching(t) ^
t.empid = d.hod
^ t.sem = ‘odd’ ^ t.year = ‘2008’)}
Examples queries in TRC (4/5) Schema
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
12
6)Determine the students who are enrolled for every
course taught by Prof Ramanujam. Assume that Prof
Ramanujam teaches at least one course.
1. {s.rollNo | student (s) ^
2. (∀c)(course (c) ^
3. ((∃t),(∃p)( teaching(t) ^ professor(p) ^
4. t.courseId = c.courseId ^
5. p.name = “Ramanujam” ^
6. p.empId = t.empId )) →
7. (∃e) (enrollment(e) ^
8. e.courseId = c.courseId ^
9. e.rollNo = s.rollNo)
10. )
11. }
Examples queries in TRC (5/5) Schema
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
13
What is the result of the query:
{s.rollNo | ¬ student(s)} ?
Infinite answers !!
Unsafe TRC expression :
Any expression whose result uses “constants / values” that do not
appear in the instances of any of the database relations.
Unsafe expressions are to be avoided while specifying TRC queries.
Problem with unrestricted use of Negation
Prof P Sreenivasa Kumar,
Department of CS&E, IITM.
14
It can be shown that
both Tuple Relational Calculus and Relational Algebra
have the same expressive power
A query can be formulated in (safe) TRC
if and only if it can be formulated in RA
Both can not be used to formulate queries involving
transitive closure
-- find all direct or indirect pre-requisites of a course
-- find all subordinates of a specific employee etc.
Expressive power of TRC and Relational Algebra

More Related Content

What's hot

Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
Temesgenthanks
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
Smriti Jain
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
Amrit Kaur
 
Database language
Database languageDatabase language
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control Techniques
Raj vardhan
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
Megha Patel
 
Dbms schema &amp; instance
Dbms schema &amp; instanceDbms schema &amp; instance
Dbms schema &amp; instance
Papan Sarkar
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalizationdaxesh chauhan
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
Arun Sharma
 
Serializability
SerializabilitySerializability
Serializability
Pyingkodi Maran
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
pnp @in
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
Chirag vasava
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
Janki Shah
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
Vraj Patel
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMSkoolkampus
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
Shakila Mahjabin
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
Prosanta Ghosh
 

What's hot (20)

Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
Database language
Database languageDatabase language
Database language
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control Techniques
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Dbms schema &amp; instance
Dbms schema &amp; instanceDbms schema &amp; instance
Dbms schema &amp; instance
 
Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalization
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
Serializability
SerializabilitySerializability
Serializability
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
 

Similar to 3.1 tuple relational_calculus

3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
SrikanthS494888
 
Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languages
jamunaashok
 
3 relational model
3 relational model3 relational model
3 relational model
Utkarsh De
 
Master’s theorem Derivative Analysis
Master’s theorem Derivative AnalysisMaster’s theorem Derivative Analysis
Master’s theorem Derivative Analysis
IRJET Journal
 
Fractional Derivatives of Some Fractional Functions and Their Applications
Fractional Derivatives of Some Fractional Functions and Their ApplicationsFractional Derivatives of Some Fractional Functions and Their Applications
Fractional Derivatives of Some Fractional Functions and Their Applications
Associate Professor in VSB Coimbatore
 
Infinite sequence & series 1st lecture
Infinite sequence & series 1st lecture Infinite sequence & series 1st lecture
Infinite sequence & series 1st lecture
Mohsin Ramay
 
ON M(M,m)/M/C/N: Interdependent Queueing Model
ON M(M,m)/M/C/N: Interdependent Queueing ModelON M(M,m)/M/C/N: Interdependent Queueing Model
ON M(M,m)/M/C/N: Interdependent Queueing Model
IOSR Journals
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standard
Utkarsh De
 
Ail apresentation(kumazawa)
Ail apresentation(kumazawa)Ail apresentation(kumazawa)
Ail apresentation(kumazawa)
TakaKumazawa
 
A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...
A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...
A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...
IJERA Editor
 
presentation at E-Learn 2008
presentation at E-Learn 2008presentation at E-Learn 2008
presentation at E-Learn 2008Dr. Popat Tambade
 
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 GraphsA Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
京都大学大学院情報学研究科数理工学専攻
 
13 sequences and series
13   sequences and series13   sequences and series
13 sequences and seriesKathManarang
 
Time Table Scheduling Problem Using Fuzzy Algorithmic Approach
Time Table Scheduling Problem Using Fuzzy Algorithmic ApproachTime Table Scheduling Problem Using Fuzzy Algorithmic Approach
Time Table Scheduling Problem Using Fuzzy Algorithmic Approach
Waqas Tariq
 
Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...
IRJET Journal
 
Module 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxModule 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptx
ShashiKumarB5
 
Hydraulic similitude and model analysis
Hydraulic similitude and model analysisHydraulic similitude and model analysis
Hydraulic similitude and model analysis
Mohsin Siddique
 
Adaptive relevance feedback in information retrieval
Adaptive relevance feedback in information retrievalAdaptive relevance feedback in information retrieval
Adaptive relevance feedback in information retrieval
YI-JHEN LIN
 
A genetic algorithm for a university weekly courses timetabling problem
A genetic algorithm for a university weekly courses timetabling problemA genetic algorithm for a university weekly courses timetabling problem
A genetic algorithm for a university weekly courses timetabling problem
Motasem Smadi
 

Similar to 3.1 tuple relational_calculus (20)

Trc final
Trc finalTrc final
Trc final
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languages
 
3 relational model
3 relational model3 relational model
3 relational model
 
Master’s theorem Derivative Analysis
Master’s theorem Derivative AnalysisMaster’s theorem Derivative Analysis
Master’s theorem Derivative Analysis
 
Fractional Derivatives of Some Fractional Functions and Their Applications
Fractional Derivatives of Some Fractional Functions and Their ApplicationsFractional Derivatives of Some Fractional Functions and Their Applications
Fractional Derivatives of Some Fractional Functions and Their Applications
 
Infinite sequence & series 1st lecture
Infinite sequence & series 1st lecture Infinite sequence & series 1st lecture
Infinite sequence & series 1st lecture
 
ON M(M,m)/M/C/N: Interdependent Queueing Model
ON M(M,m)/M/C/N: Interdependent Queueing ModelON M(M,m)/M/C/N: Interdependent Queueing Model
ON M(M,m)/M/C/N: Interdependent Queueing Model
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standard
 
Ail apresentation(kumazawa)
Ail apresentation(kumazawa)Ail apresentation(kumazawa)
Ail apresentation(kumazawa)
 
A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...
A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...
A Mathematical Model to Solve Nonlinear Initial and Boundary Value Problems b...
 
presentation at E-Learn 2008
presentation at E-Learn 2008presentation at E-Learn 2008
presentation at E-Learn 2008
 
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 GraphsA Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
 
13 sequences and series
13   sequences and series13   sequences and series
13 sequences and series
 
Time Table Scheduling Problem Using Fuzzy Algorithmic Approach
Time Table Scheduling Problem Using Fuzzy Algorithmic ApproachTime Table Scheduling Problem Using Fuzzy Algorithmic Approach
Time Table Scheduling Problem Using Fuzzy Algorithmic Approach
 
Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...Solution of Ordinary Differential Equation with Initial Condition Using New E...
Solution of Ordinary Differential Equation with Initial Condition Using New E...
 
Module 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxModule 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptx
 
Hydraulic similitude and model analysis
Hydraulic similitude and model analysisHydraulic similitude and model analysis
Hydraulic similitude and model analysis
 
Adaptive relevance feedback in information retrieval
Adaptive relevance feedback in information retrievalAdaptive relevance feedback in information retrieval
Adaptive relevance feedback in information retrieval
 
A genetic algorithm for a university weekly courses timetabling problem
A genetic algorithm for a university weekly courses timetabling problemA genetic algorithm for a university weekly courses timetabling problem
A genetic algorithm for a university weekly courses timetabling problem
 

More from Utkarsh De

4 k Display Technology
4 k Display Technology4 k Display Technology
4 k Display Technology
Utkarsh De
 
6 relational schema_design
6 relational schema_design6 relational schema_design
6 relational schema_design
Utkarsh De
 
5 data storage_and_indexing
5 data storage_and_indexing5 data storage_and_indexing
5 data storage_and_indexing
Utkarsh De
 
2 entity relationship_model
2 entity relationship_model2 entity relationship_model
2 entity relationship_model
Utkarsh De
 
1 introduction
1 introduction1 introduction
1 introduction
Utkarsh De
 
Four way traffic light conrol using Verilog
Four way traffic light conrol using VerilogFour way traffic light conrol using Verilog
Four way traffic light conrol using Verilog
Utkarsh De
 

More from Utkarsh De (6)

4 k Display Technology
4 k Display Technology4 k Display Technology
4 k Display Technology
 
6 relational schema_design
6 relational schema_design6 relational schema_design
6 relational schema_design
 
5 data storage_and_indexing
5 data storage_and_indexing5 data storage_and_indexing
5 data storage_and_indexing
 
2 entity relationship_model
2 entity relationship_model2 entity relationship_model
2 entity relationship_model
 
1 introduction
1 introduction1 introduction
1 introduction
 
Four way traffic light conrol using Verilog
Four way traffic light conrol using VerilogFour way traffic light conrol using Verilog
Four way traffic light conrol using Verilog
 

Recently uploaded

CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 

Recently uploaded (20)

CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 

3.1 tuple relational_calculus

  • 1. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 1 Tuple Relational Calculus ( TRC ) Introduction Procedural Query language query specification involves giving a step by step process of obtaining the query result e.g., relational algebra usage calls for detailed knowledge of the operators involved difficult for the use of non-experts Declarative Query language query specification involves giving the logical conditions the results are required to satisfy easy for the use of non-experts
  • 2. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 2 TRC – a declarative query language Tuple variable – associated with a relation ( called the range relation ) • takes tuples from the range relation as its values • t: tuple variable over relation r with scheme R(A,B,C ) t.A stands for value of column A etc TRC Query – basic form: { t1.Ai1 , t2.Ai2 ,…tm.Aim | θ } predicate calculus expression involving tuple variables t1, t2,…, tm, tm+1,…,ts - specifies the condition to be satisfied
  • 3. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 3 An example TRC query student (rollNo, name, degree, year, sex, deptNo, advisor ) department (deptId, name, hod, phone ) Obtain the rollNo, name of all girl students in the Maths Dept (deptId = 2) {s.rollNo,s.name| student(s)^ s.sex=‘F’^ s.deptNo=2} attributes required in the result This predicate is true whenever value of s is a tuple from the student relation, false otherwise In general, if t is a tuple variable with range relation r, r( t ) is taken as a predicate which is true if and only if the value of t is a tuple in r
  • 4. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 4 Atomic expressions are the following: 1. r ( t ) -- true if t is a tuple in the relation instance r 2. t1. Ai <compOp> t2 .Aj compOp is one of {<, ≤ , >, ≥, =, ≠ } 3. t.Ai <compOp> c c is a constant of appropriate type Composite expressions: 1. Any atomic expression 2. F1 ∧ F2 ,, F1 ∨ F2 , ¬ F1 where F1 and F2 are expressions 3. (∀t) (F), (∃t) (F) where F is an expression and t is a tuple variable Free Variables Bound Variables – quantified variables General form of the condition in TRC queries
  • 5. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 5 All possible tuple assignments to the free variables in the query are considered. For any specific assignment, if the expression to the right of the vertical bar evaluates to true, that combination of tuple values would be used to produce a tuple in the result relation. While producing the result tuple, the values of the attributes for the corresponding tuple variables as specified on the left side of the vertical bar would be used. Note: The only free variables are the ones that appear to the left of the vertical bar Interpretation of the query in TRC
  • 6. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 6 Obtain the rollNo, name of all girl students in the Maths Dept {s.rollNo,s.name | student(s) ^ s.sex=‘F’ ^ (∃ d)(department(d) ^ d.name=‘Maths’ ^ d.deptId = s.deptNo)} s: free tuple variable d: existentially bound tuple variable Existentially or universally quantified tuple variables can be used on the RHS of the vertical bar to specify query conditions Attributes of free (or unbound ) tuple variables can be used on LHS of vertical bar to specify attributes required in the results Example TRC queries
  • 7. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 7 Example Relational Scheme student (rollNo, name, degree, year, sex, deptNo, advisor) department (deptId, name, hod, phone) professor (empId, name, sex, startYear, deptNo, phone) course (courseId, cname, credits, deptNo) enrollment (rollNo, courseId, sem, year, grade) teaching (empId, courseId, sem, year, classRoom) preRequisite (preReqCourse, courseID) Q2 Q3 Q4 Q5
  • 8. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 8 Example queries in TRC (1/5) 1)Determine the departments that do not have any girl students student (rollNo, name, degree, year, sex, deptNo, advisor) department (deptId, name, hod, phone) {d.name|department(d) ^ ¬(∃ s)(student(s) ^ s.sex =‘F’ ^ s.deptNo = d.deptId)
  • 9. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 9 2)Obtain the names of courses enrolled by student named Mahesh {c.name | course(c) ^ (∃s) (∃e) ( student(s) ^ enrollment(e) ^ s.name = “Mahesh” ^ s.rollNo = e.rollNo ^ c.courseId = e.courseId } Examples queries in TRC (2/5) Schema
  • 10. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 10 3)Get the names of students who have scored ‘S’ in all subjects they have enrolled. Assume that every student is enrolled in at least one course. {s.name | student(s) ^ (∀e)(( enrollment(e) ^ e.rollNo = s.rollNo) → e.grade =‘S’)} person P with all S grades: for enrollment tuples not having her roll number, LHS is false for enrollment tuples having her roll number, LHS is true, RHS also true so the implication is true for all e tuples person Q with some non-S grades: for enrollment tuples not having her roll number, LHS is false for enrollment tuples having her roll number, LHS is true, but RHS is false for at least one tuple. So the implication is not true for at least one tuple. Examples queries in TRC (3/5) Schema
  • 11. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 11 4) Get the names of students who have taken at least one course taught by their advisor {s.name | student(s) ^ (∃e)(∃t)(enrollment(e) ^ teaching(t) ^ e.courseId = t.courseId ^ e.rollNo = s.rollNo ^ t.empId = s.advisor} 5) Display the departments whose HODs are teaching at least one course in the current semester {d.name | department(d) ^(∃t)(teaching(t) ^ t.empid = d.hod ^ t.sem = ‘odd’ ^ t.year = ‘2008’)} Examples queries in TRC (4/5) Schema
  • 12. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 12 6)Determine the students who are enrolled for every course taught by Prof Ramanujam. Assume that Prof Ramanujam teaches at least one course. 1. {s.rollNo | student (s) ^ 2. (∀c)(course (c) ^ 3. ((∃t),(∃p)( teaching(t) ^ professor(p) ^ 4. t.courseId = c.courseId ^ 5. p.name = “Ramanujam” ^ 6. p.empId = t.empId )) → 7. (∃e) (enrollment(e) ^ 8. e.courseId = c.courseId ^ 9. e.rollNo = s.rollNo) 10. ) 11. } Examples queries in TRC (5/5) Schema
  • 13. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 13 What is the result of the query: {s.rollNo | ¬ student(s)} ? Infinite answers !! Unsafe TRC expression : Any expression whose result uses “constants / values” that do not appear in the instances of any of the database relations. Unsafe expressions are to be avoided while specifying TRC queries. Problem with unrestricted use of Negation
  • 14. Prof P Sreenivasa Kumar, Department of CS&E, IITM. 14 It can be shown that both Tuple Relational Calculus and Relational Algebra have the same expressive power A query can be formulated in (safe) TRC if and only if it can be formulated in RA Both can not be used to formulate queries involving transitive closure -- find all direct or indirect pre-requisites of a course -- find all subordinates of a specific employee etc. Expressive power of TRC and Relational Algebra