SlideShare a Scribd company logo
1 of 26
Download to read offline
By
S.Jamuna
Assistant Professor
Bon Secours College for Women
Thanjavur
 Relational Algebra
 Tuple Relational Calculus
 Domain Relational Calculus
 Procedural language
 Six basic operators
◦ select: 
◦ project: 
◦ union: 
◦ set difference: –
◦ Cartesian product: x
◦ rename: 
 The operators take one or two relations
as inputs and produce a new relation as a
result.
 Notation:  p(r)
 p is called the selection predicate
 Defined as:
p(r) = {t | t  r and p(t)}
Where p is a formula in propositional calculus consisting of
terms connected by :  (and),  (or),  (not)
Each term is one of:
<attribute> op <attribute> or <constant>
where op is one of: =, , >, . <. 
 Example of selection:
 dept_name=“Physics”(instructor)
 Notation:
where A1, A2 are attribute names and r is a
relation name.
 The result is defined as the relation of k
columns obtained by erasing the columns that
are not listed
 Duplicate rows removed from result, since
relations are sets
 Example: To eliminate the dept_name attribute
of instructor
ID, name, salary (instructor)
)(,,2,1
r
kAAA 
 Notation: r  s
 Defined as:
r  s = {t | t  r or t  s}
 For r  s to be valid.
1. r, s must have the same arity (same number of
attributes)
2. The attribute domains must be compatible
(example: 2nd column
of r deals with the same type of values as does the
2nd
column of s)
 Example: to find all courses taught in the Fall 2009
semester, or in the Spring 2010 semester, or in both
course_id ( semester=“Fall” Λ year=2009 (section)) 
course_id ( semester=“Spring” Λ year=2010 (section))
 Notation r – s
 Defined as:
r – s = {t | t  r and t  s}
 Set differences must be taken between compatible
relations.
◦ r and s must have the same arity
◦ attribute domains of r and s must be compatible
 Example: to find all courses taught in the Fall 2009
semester, but not in the Spring 2010 semester
course_id ( semester=“Fall” Λ year=2009
(section)) −
course_id ( semester=“Spring” Λ year=2010
(section))
 Notation: r  s
 Defined as:
 r  s = { t | t  r and t  s }
 Assume:
◦ r, s have the same arity
◦ attributes of r and s are compatible
 Note: r  s = r – (r – s)
 Notation r x s
 Defined as:
r x s = {t q | t  r and q  s}
 Assume that attributes of r(R)
and s(S) are disjoint. (That is,
R  S = ).
 If attributes of r(R) and s(S)
are not disjoint, then
renaming must be used.
 Allows us to name, and therefore to refer to, the
results of relational-algebra expressions.
 Allows us to refer to a relation by more than one
name.
 Example:
 x (E)
returns the expression E under the name X
 If a relational-algebra expression E has arity n,
then
returns the result of expression E under the name
X, and with the
attributes renamed to A1 , A2 , …., An .
)(),...,2,1( E
nAAAx
 A basic expression in the relational algebra
consists of either one of the following:
◦ A relation in the database
◦ A constant relation
 Let E1 and E2 be relational-algebra
expressions; the following are all relational-
algebra expressions:
◦ E1  E2
◦ E1 – E2
◦ E1 x E2
◦ p (E1), P is a predicate on attributes in E1
◦ s(E1), S is a list consisting of some of the attributes
in E1
◦  x (E1), x is the new name for the result of E1
 A nonprocedural query language, where each query
is of the form
{t | P (t ) }
 It is the set of all tuples t such that predicate P is
true for t
 t is a tuple variable, t [A ] denotes the value of tuple t
on attribute A
 t  r denotes that tuple t is in relation r
 P is a formula similar to that of the predicate
calculus
1. Set of attributes and constants
2. Set of comparison operators: (e.g., , , =,
, , )
3. Set of connectives: and (), or (v)‚ not ()
4. Implication (): x  y, if x if true, then y is
true
x  y  x v y
5. Set of quantifiers:
 t  r (Q (t ))  ”there exists” a tuple in 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
 Find the ID, name, dept_name, salary for
instructors whose salary is greater than $80,000
As in the previous query, but output only the ID attribute value
{t |  s  instructor (t [ID ] = s [ID ]  s [salary ]  80000)}
{t | t  instructor  t [salary ]  80000}
Notice that a relation on schema (ID) is implicitly defined by
the query
Notice that a relation on schema (ID, name, dept_name, salary) is
implicitly defined by the query
 Find the names of all instructors whose
department is in the Watson building
{t | s  section (t [course_id ] = s [course_id ] 
s [semester] = “Fall”  s [year] = 2009
v u  section (t [course_id ] = u [course_id ] 
u [semester] = “Spring”  u [year] = 2010 )}
Find the set of all courses taught in the Fall 2009 semester, or in
the Spring 2010 semester, or both
{t | s  instructor (t [name ] = s [name ]
 u  department (u [dept_name ] = s[dept_name] “
 u [building] = “Watson” ))}
{t | s  section (t [course_id ] = s [course_id ] 
s [semester] = “Fall”  s [year] = 2009
 u  section (t [course_id ] = u [course_id ] 
u [semester] = “Spring”  u [year] = 2010 )}
Find the set of all courses taught in the Fall 2009 semester, and in
the Spring 2010 semester
{t | s  section (t [course_id ] = s [course_id ] 
s [semester] = “Fall”  s [year] = 2009
  u  section (t [course_id ] = u [course_id ] 
u [semester] = “Spring”  u [year] = 2010 )}
Find the set of all courses taught in the Fall 2009 semester, but not in
the Spring 2010 semester
 Find all students who have taken all courses offered in the
Biology department
◦ {t |  r  student (t [ID] = r [ID]) 
( u  course (u [dept_name]=“Biology” 
 s  takes (t [ID] = s [ID ] 
s [course_id] = u [course_id]))}
 It is possible to write tuple calculus expressions
that generate infinite relations.
 For example, { t |  t  r } results in an infinite
relation if the domain of any attribute of
relation r is infinite
 To guard against the problem, we restrict the
set of allowable expressions to safe
expressions.
 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 P
◦ NOTE: this is more than just a syntax condition.
 E.g. { t | t [A] = 5  true } is not safe --- it defines an
infinite set with attribute values that do not appear in
any relation or tuples or constants in P.
 Consider again that query to find all students who have taken
all courses offered in the Biology department
◦ {t |  r  student (t [ID] = r [ID]) 
( u  course (u [dept_name]=“Biology” 
 s  takes (t [ID] = s [ID ] 
s [course_id] = u [course_id]))}
 Without the existential quantification on student, the above
query would be unsafe if the Biology department has not
offered any courses.
 A nonprocedural query language equivalent
in power to the tuple relational calculus
 Each query is an expression of the form:
{  x1, x2, …, xn  | P (x1, x2, …, xn)}
◦ x1, x2, …, xn represent domain variables
◦ P represents a formula similar to that of the
predicate calculus
 Find the ID, name, dept_name, salary for
instructors whose salary is greater than $80,000
◦ {< i, n, d, s> | < i, n, d, s>  instructor  s  80000}
 As in the previous query, but output only the ID
attribute value
◦ {< i> | < i, n, d, s>  instructor  s  80000}
 Find the names of all instructors whose
department is in the Watson building
{< n > |  i, d, s (< i, n, d, s >  instructor
  b, a (< d, b, a>  department  b
= “Watson” ))}
{<c> |  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section 
s = “Fall”  y = 2009 )
v  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section ] 
s = “Spring”  y = 2010)}
Find the set of all courses taught in the Fall 2009 semester, or in
the Spring 2010 semester, or both
This case can also be written as
{<c> |  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section 
( (s = “Fall”  y = 2009 ) v (s = “Spring”  y = 2010))}
Find the set of all courses taught in the Fall 2009 semester, and in
the Spring 2010 semester
{<c> |  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section 
s = “Fall”  y = 2009 )
  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section ] 
s = “Spring”  y = 2010)}
The expression:
{  x1, x2, …, xn  | P (x1, x2, …, xn )}
is safe if all of the following hold:
1. All values that appear in tuples of the expression
are values from dom (P ) (that is, the values appear
either in P or in a tuple of a relation mentioned in
P ).
2. For every “there exists” subformula of the form  x
(P1(x )), the subformula is true if and only if there is
a value of x in dom (P1)such that P1(x ) is true.
3. For every “for all” subformula of the form x (P1 (x
)), the subformula is true if and only if P1(x ) is true
for all values x from dom (P1).
Database systems-Formal relational query languages

More Related Content

What's hot

Relations & functions.pps
Relations  &  functions.ppsRelations  &  functions.pps
Relations & functions.ppsindu psthakur
 
7_Intro_to_Functions
7_Intro_to_Functions7_Intro_to_Functions
7_Intro_to_Functionsnechamkin
 
Objective 1 - Identifying Functions
Objective 1 - Identifying FunctionsObjective 1 - Identifying Functions
Objective 1 - Identifying Functionsguestd3e8a33
 
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeksBeginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeksJinTaek Seo
 
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeksBeginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeksJinTaek Seo
 
Eighan values and diagonalization
Eighan values and diagonalization Eighan values and diagonalization
Eighan values and diagonalization gandhinagar
 
Integration presentation
Integration presentationIntegration presentation
Integration presentationUrmila Bhardwaj
 
THE CALCULUS INTEGRAL (Beta Version 2009)
THE CALCULUS INTEGRAL (Beta Version 2009)THE CALCULUS INTEGRAL (Beta Version 2009)
THE CALCULUS INTEGRAL (Beta Version 2009)briansthomson
 

What's hot (17)

Relations & functions.pps
Relations  &  functions.ppsRelations  &  functions.pps
Relations & functions.pps
 
function
functionfunction
function
 
Blackbox task 2
Blackbox task 2Blackbox task 2
Blackbox task 2
 
7_Intro_to_Functions
7_Intro_to_Functions7_Intro_to_Functions
7_Intro_to_Functions
 
Task 4
Task 4Task 4
Task 4
 
test
testtest
test
 
Math task 3
Math task 3Math task 3
Math task 3
 
Functions in mathematics
Functions in mathematicsFunctions in mathematics
Functions in mathematics
 
Objective 1 - Identifying Functions
Objective 1 - Identifying FunctionsObjective 1 - Identifying Functions
Objective 1 - Identifying Functions
 
Functions
FunctionsFunctions
Functions
 
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeksBeginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
 
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeksBeginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
 
Eighan values and diagonalization
Eighan values and diagonalization Eighan values and diagonalization
Eighan values and diagonalization
 
L16
L16L16
L16
 
Per6 basis2_NUMBER SYSTEMS
Per6 basis2_NUMBER SYSTEMSPer6 basis2_NUMBER SYSTEMS
Per6 basis2_NUMBER SYSTEMS
 
Integration presentation
Integration presentationIntegration presentation
Integration presentation
 
THE CALCULUS INTEGRAL (Beta Version 2009)
THE CALCULUS INTEGRAL (Beta Version 2009)THE CALCULUS INTEGRAL (Beta Version 2009)
THE CALCULUS INTEGRAL (Beta Version 2009)
 

Similar to Database systems-Formal relational query languages

DBMS Formal Relational Query Languages Relational Calculus.pdf
DBMS Formal Relational Query Languages Relational Calculus.pdfDBMS Formal Relational Query Languages Relational Calculus.pdf
DBMS Formal Relational Query Languages Relational Calculus.pdfestorebackupr
 
2.1 Basics of Functions and Their Graphs
2.1 Basics of Functions and Their Graphs2.1 Basics of Functions and Their Graphs
2.1 Basics of Functions and Their Graphssmiller5
 
Introduction to Relational Database Management Systems
Introduction to Relational Database Management SystemsIntroduction to Relational Database Management Systems
Introduction to Relational Database Management SystemsAdri Jovin
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operationsSanthiNivas
 
Ch6 formal relational query languages
Ch6 formal relational query languages Ch6 formal relational query languages
Ch6 formal relational query languages uoitc
 
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-2013Prosanta Ghosh
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusemailharmeet
 
3.1 tuple relational_calculus
3.1 tuple relational_calculus3.1 tuple relational_calculus
3.1 tuple relational_calculusUtkarsh De
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasexabhaysonone0
 
3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebra3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebraZakriyaMalik2
 

Similar to Database systems-Formal relational query languages (20)

ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
DBMS Formal Relational Query Languages Relational Calculus.pdf
DBMS Formal Relational Query Languages Relational Calculus.pdfDBMS Formal Relational Query Languages Relational Calculus.pdf
DBMS Formal Relational Query Languages Relational Calculus.pdf
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
Ra Revision
Ra RevisionRa Revision
Ra Revision
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
2.1 Basics of Functions and Their Graphs
2.1 Basics of Functions and Their Graphs2.1 Basics of Functions and Their Graphs
2.1 Basics of Functions and Their Graphs
 
Introduction to Relational Database Management Systems
Introduction to Relational Database Management SystemsIntroduction to Relational Database Management Systems
Introduction to Relational Database Management Systems
 
L4_SQL.pdf
L4_SQL.pdfL4_SQL.pdf
L4_SQL.pdf
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
 
1643 y є r relational calculus-1
1643 y є r  relational calculus-11643 y є r  relational calculus-1
1643 y є r relational calculus-1
 
Ch2
Ch2Ch2
Ch2
 
Ch6 formal relational query languages
Ch6 formal relational query languages Ch6 formal relational query languages
Ch6 formal relational query languages
 
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
 
Trc final
Trc finalTrc final
Trc final
 
Cs501 trc drc
Cs501 trc drcCs501 trc drc
Cs501 trc drc
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
3.1 tuple relational_calculus
3.1 tuple relational_calculus3.1 tuple relational_calculus
3.1 tuple relational_calculus
 
relational algebra
relational algebrarelational algebra
relational algebra
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex
 
3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebra3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebra
 

More from jamunaashok

Computer networks transport layer
Computer networks  transport layerComputer networks  transport layer
Computer networks transport layerjamunaashok
 
Corel draw shortcut keys
Corel draw shortcut keysCorel draw shortcut keys
Corel draw shortcut keysjamunaashok
 
Relational database oracle
Relational database  oracleRelational database  oracle
Relational database oraclejamunaashok
 
Deadlock in operating systems
Deadlock in operating systemsDeadlock in operating systems
Deadlock in operating systemsjamunaashok
 
Packages in java
Packages in javaPackages in java
Packages in javajamunaashok
 
Data storage in cloud computing
Data storage in cloud computingData storage in cloud computing
Data storage in cloud computingjamunaashok
 

More from jamunaashok (6)

Computer networks transport layer
Computer networks  transport layerComputer networks  transport layer
Computer networks transport layer
 
Corel draw shortcut keys
Corel draw shortcut keysCorel draw shortcut keys
Corel draw shortcut keys
 
Relational database oracle
Relational database  oracleRelational database  oracle
Relational database oracle
 
Deadlock in operating systems
Deadlock in operating systemsDeadlock in operating systems
Deadlock in operating systems
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Data storage in cloud computing
Data storage in cloud computingData storage in cloud computing
Data storage in cloud computing
 

Recently uploaded

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 

Recently uploaded (20)

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 

Database systems-Formal relational query languages

  • 1. By S.Jamuna Assistant Professor Bon Secours College for Women Thanjavur
  • 2.  Relational Algebra  Tuple Relational Calculus  Domain Relational Calculus
  • 3.  Procedural language  Six basic operators ◦ select:  ◦ project:  ◦ union:  ◦ set difference: – ◦ Cartesian product: x ◦ rename:   The operators take one or two relations as inputs and produce a new relation as a result.
  • 4.  Notation:  p(r)  p is called the selection predicate  Defined as: p(r) = {t | t  r and p(t)} Where p is a formula in propositional calculus consisting of terms connected by :  (and),  (or),  (not) Each term is one of: <attribute> op <attribute> or <constant> where op is one of: =, , >, . <.   Example of selection:  dept_name=“Physics”(instructor)
  • 5.  Notation: where A1, A2 are attribute names and r is a relation name.  The result is defined as the relation of k columns obtained by erasing the columns that are not listed  Duplicate rows removed from result, since relations are sets  Example: To eliminate the dept_name attribute of instructor ID, name, salary (instructor) )(,,2,1 r kAAA 
  • 6.  Notation: r  s  Defined as: r  s = {t | t  r or t  s}  For r  s to be valid. 1. r, s must have the same arity (same number of attributes) 2. The attribute domains must be compatible (example: 2nd column of r deals with the same type of values as does the 2nd column of s)  Example: to find all courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or in both course_id ( semester=“Fall” Λ year=2009 (section))  course_id ( semester=“Spring” Λ year=2010 (section))
  • 7.  Notation r – s  Defined as: r – s = {t | t  r and t  s}  Set differences must be taken between compatible relations. ◦ r and s must have the same arity ◦ attribute domains of r and s must be compatible  Example: to find all courses taught in the Fall 2009 semester, but not in the Spring 2010 semester course_id ( semester=“Fall” Λ year=2009 (section)) − course_id ( semester=“Spring” Λ year=2010 (section))
  • 8.  Notation: r  s  Defined as:  r  s = { t | t  r and t  s }  Assume: ◦ r, s have the same arity ◦ attributes of r and s are compatible  Note: r  s = r – (r – s)
  • 9.  Notation r x s  Defined as: r x s = {t q | t  r and q  s}  Assume that attributes of r(R) and s(S) are disjoint. (That is, R  S = ).  If attributes of r(R) and s(S) are not disjoint, then renaming must be used.
  • 10.  Allows us to name, and therefore to refer to, the results of relational-algebra expressions.  Allows us to refer to a relation by more than one name.  Example:  x (E) returns the expression E under the name X  If a relational-algebra expression E has arity n, then returns the result of expression E under the name X, and with the attributes renamed to A1 , A2 , …., An . )(),...,2,1( E nAAAx
  • 11.  A basic expression in the relational algebra consists of either one of the following: ◦ A relation in the database ◦ A constant relation  Let E1 and E2 be relational-algebra expressions; the following are all relational- algebra expressions: ◦ E1  E2 ◦ E1 – E2 ◦ E1 x E2 ◦ p (E1), P is a predicate on attributes in E1 ◦ s(E1), S is a list consisting of some of the attributes in E1 ◦  x (E1), x is the new name for the result of E1
  • 12.
  • 13.  A nonprocedural query language, where each query is of the form {t | P (t ) }  It is the set of all tuples t such that predicate P is true for t  t is a tuple variable, t [A ] denotes the value of tuple t on attribute A  t  r denotes that tuple t is in relation r  P is a formula similar to that of the predicate calculus
  • 14. 1. Set of attributes and constants 2. Set of comparison operators: (e.g., , , =, , , ) 3. Set of connectives: and (), or (v)‚ not () 4. Implication (): x  y, if x if true, then y is true x  y  x v y 5. Set of quantifiers:  t  r (Q (t ))  ”there exists” a tuple in 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
  • 15.  Find the ID, name, dept_name, salary for instructors whose salary is greater than $80,000 As in the previous query, but output only the ID attribute value {t |  s  instructor (t [ID ] = s [ID ]  s [salary ]  80000)} {t | t  instructor  t [salary ]  80000} Notice that a relation on schema (ID) is implicitly defined by the query Notice that a relation on schema (ID, name, dept_name, salary) is implicitly defined by the query
  • 16.  Find the names of all instructors whose department is in the Watson building {t | s  section (t [course_id ] = s [course_id ]  s [semester] = “Fall”  s [year] = 2009 v u  section (t [course_id ] = u [course_id ]  u [semester] = “Spring”  u [year] = 2010 )} Find the set of all courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or both {t | s  instructor (t [name ] = s [name ]  u  department (u [dept_name ] = s[dept_name] “  u [building] = “Watson” ))}
  • 17. {t | s  section (t [course_id ] = s [course_id ]  s [semester] = “Fall”  s [year] = 2009  u  section (t [course_id ] = u [course_id ]  u [semester] = “Spring”  u [year] = 2010 )} Find the set of all courses taught in the Fall 2009 semester, and in the Spring 2010 semester {t | s  section (t [course_id ] = s [course_id ]  s [semester] = “Fall”  s [year] = 2009   u  section (t [course_id ] = u [course_id ]  u [semester] = “Spring”  u [year] = 2010 )} Find the set of all courses taught in the Fall 2009 semester, but not in the Spring 2010 semester
  • 18.  Find all students who have taken all courses offered in the Biology department ◦ {t |  r  student (t [ID] = r [ID])  ( u  course (u [dept_name]=“Biology”   s  takes (t [ID] = s [ID ]  s [course_id] = u [course_id]))}
  • 19.  It is possible to write tuple calculus expressions that generate infinite relations.  For example, { t |  t  r } results in an infinite relation if the domain of any attribute of relation r is infinite  To guard against the problem, we restrict the set of allowable expressions to safe expressions.  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 P ◦ NOTE: this is more than just a syntax condition.  E.g. { t | t [A] = 5  true } is not safe --- it defines an infinite set with attribute values that do not appear in any relation or tuples or constants in P.
  • 20.  Consider again that query to find all students who have taken all courses offered in the Biology department ◦ {t |  r  student (t [ID] = r [ID])  ( u  course (u [dept_name]=“Biology”   s  takes (t [ID] = s [ID ]  s [course_id] = u [course_id]))}  Without the existential quantification on student, the above query would be unsafe if the Biology department has not offered any courses.
  • 21.
  • 22.  A nonprocedural query language equivalent in power to the tuple relational calculus  Each query is an expression of the form: {  x1, x2, …, xn  | P (x1, x2, …, xn)} ◦ x1, x2, …, xn represent domain variables ◦ P represents a formula similar to that of the predicate calculus
  • 23.  Find the ID, name, dept_name, salary for instructors whose salary is greater than $80,000 ◦ {< i, n, d, s> | < i, n, d, s>  instructor  s  80000}  As in the previous query, but output only the ID attribute value ◦ {< i> | < i, n, d, s>  instructor  s  80000}  Find the names of all instructors whose department is in the Watson building {< n > |  i, d, s (< i, n, d, s >  instructor   b, a (< d, b, a>  department  b = “Watson” ))}
  • 24. {<c> |  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section  s = “Fall”  y = 2009 ) v  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section ]  s = “Spring”  y = 2010)} Find the set of all courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or both This case can also be written as {<c> |  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section  ( (s = “Fall”  y = 2009 ) v (s = “Spring”  y = 2010))} Find the set of all courses taught in the Fall 2009 semester, and in the Spring 2010 semester {<c> |  a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section  s = “Fall”  y = 2009 )   a, s, y, b, r, t ( <c, a, s, y, b, r, t >  section ]  s = “Spring”  y = 2010)}
  • 25. The expression: {  x1, x2, …, xn  | P (x1, x2, …, xn )} is safe if all of the following hold: 1. All values that appear in tuples of the expression are values from dom (P ) (that is, the values appear either in P or in a tuple of a relation mentioned in P ). 2. For every “there exists” subformula of the form  x (P1(x )), the subformula is true if and only if there is a value of x in dom (P1)such that P1(x ) is true. 3. For every “for all” subformula of the form x (P1 (x )), the subformula is true if and only if P1(x ) is true for all values x from dom (P1).