SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Relational Algebra
1
Fall 2001 Database Systems 1
Relational Algebra
• A relation is a set of tuples. Each relational
algebra operation takes as input a list of
relations and produces a single relation.
• General form:
OperatorArguments (List of Relations)
 
New Relation
• After each operation, the remaining attributes
are carried to the new relation. The attributes
may be renamed, but their domain remains the
same.
Fall 2001 Database Systems 2
Set Theoretic Operations
• Regular set operations on relations
• A set operation requires two participating relations R and
S to be compatible
– R and S should have the same attributes
• R(Name:D1, Email:D2)
• S(Name:D1, Email:D2, Address:D3)
• T(Name:D1, Email:D4)
• V(Name:D1, Email:D2)
Which relations above are union (set operation)
compatible?
– Union compatibility may require type conversion
(casting).
Relational Algebra
2
Fall 2001 Database Systems 3
Set Operations
 ¢¡¤£¦¥ §©¨£ ¥¡  ! #¤$%¥(')0¥$¡1$) 
243©5 673
SR ∪
8 9 @BADC7E F©GIHQP©RDHSR©T¤F
F 5H QPUFVT 5 3 8 6 T 9
W 3 H¤FVTGQFVXYH 56 V3
SR ∩
8 9 @BADC7E F©GIHQP©RDHSR©T¤F
` 6 HDP 5 3 8aR 3Yb 9
c 5d Qd FVT¤F 3 XQF
SR −
8 9 @BADC7E F©GIHQP©RDHSR©T¤F 5 3
8e`¦AQH 36 H 5 3 9
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Fall 2001 Database Systems 4
pYq¢rs0t%u pQvw r¤x€y¤ ‚yx0vƒ
„Y… †(‡Yˆ‰  Smith@aol.com
„Y‘ ’“€”€•—– Johns@geocities.com
˜™ d0e “gf)• Brown@netmail.com
˜h i1e j—k Gray@microsoft.com
l0m)n)o0p0q l‚r s0tu vw‚xy o0x w0tz
{%| })~  € Gray@microsoft,com
{% ‚‚ƒ‚„g…‚~ † ‡ Robert432@aol.com
{0ˆ ‰ƒgŠ‚‹—‡ Johns@somewhere.com
{€Œ ‰—‡ ƒg‹ Jj@yahoo.com
{0 Ž(g—… Duke@jazz.com‘g’¤“0”Q• ‘0–— ˜Q–— ™š‚›œ —–ž—Ÿ  g¡ œ ¢g£gž š€Ÿ—–£g¤
¥%¦ §Y¦ ¨)© ª‚«¬‚­ ®€¯€­ ° ¯g±
¥%² §Y² ³1´µgµ€´± ¶U®%´· ¸ ¹ ¯gº—­ ° ¯€±
¥0» §Y² ¼¬%«¬‚­ © ¯gµ—¬ ½¤¬€¾¦¿¯€· À
¥€Á §» ‚¯gäµ—ª—­ ­ ³ª‚« «ª—­
Ä0Å ÆÇ ÈÉ Ê€Ëg̤͂ʂΗςÐ
É€ÑÒ Ó—Ô Ô Ê ÕÖ
Ó—× ×—Ø
Ö
Ä0Ù ÆYÚ Æ¤Û€ÑË—ÜÝÉ€ÑÛ
Ö Þ
Ê€Ô × Êgß
à‚áâ%ã à%äå â%æ€ç è á‚äå à0é—êgá€å ë1ì¤í—égî ç
ï0ðñ%ò ó0ô—õ€ö ÷%ò ïø òù
ï0ðñ%ø ó0ô—õ€ö ÷gú ï%ù û0ù
ï0ðñ0õ ó0ô—õ%ò ÷%ò ï€ú òó
ï0ðñgú ü%ôgò ÷0ù ï%ù ý%ù
ï0ðñ0ù ü%ôgò ÷%ò ïø øgö
ï0ðñ0û ü%ôgø ÷gú ï€ú ý‚ö
ï0ðñ‚ý ü%ôgø ÷%ø ïò ú
ï0ðñ0ó ü%ô—õ ÷%ø ï%õ ù
Relational Algebra
3
Fall 2001 Database Systems 5
Assignment and Alias
• Given a relation R, head(R)=A1…An is the list of attributes
in R.
• For each attribute, dom(A) gives the domain of A,
name(A) gives the name of the attribute
• Suppose B1…Bn is a list of attributes such that for each i,
dom(Bi) = dom(Ai)
Then assignment (:=) changes the names of some or all of
the attributes in R and results in a new relation S,
S(B1…Bn) := R(A1…An)
and dom(B1) = dom(A1) … dom(Bn) = dom(An).
Fall 2001 Database Systems 6
Set Operations
• Find all people who are registered as buyers or owners
 ¢¡¤£¦¥¨§©   ! ! #
$% ')(10 243 Smith@aol.com
$65 798@3¤ACB Johns@geocities.com
DE% F¦GIHCP Gray@microsoft.com
QRQRQ QRQ@Q QRQRQ
BUYERS-2(oid,name,email) :=
BUYERS(buyid,name,email)
RESULT := BUYERS-2 ∪ OWNERS
Relational Algebra
4
Fall 2001 Database Systems 7
Set Operations
• Find all people who are owners but not buyers
 ¢¡¤£¦¥¨§©   ! !¤ #
$% ')(0 132 Smith@aol.com
$4 5768293@ Johns@geocities.com
$¨A B¦CED3F Gray@microsoft.com
G G G
BUYERS-2(oid,name,email) :=
BUYERS(buyid,name,email)
RESULT:= OWNERS - BUYERS-2
Fall 2001 Database Systems 8
Set Operations
• Find all people who are both owners and buyers
HPI7QSRUTV WYX ` acb7dUe e7dUbfXhg
BUYERS-2(oid,name,email) :=
BUYERS(buyid,name,email)
RESULT := OWNERS ∩ BUYERS-2
Relational Algebra
5
Fall 2001 Database Systems 9
Projection
• Select all tuples from relation R, restrict each tuple to the
input attributes
– written as R[A1…An] or
for attributes A1…An from R
– meaning
nAA ...1
π
for each tuple in R
construct a new tuple containing
only attributes A1…An
place the new tuple in the result
end-for
remove duplicate tuples to preserve
the set property
Fall 2001 Database Systems 10
Projection
• Find the names and email addresses of people who are
both buyers and owners
 ¢¡¤£¦¥¨§©  !#
$%('0) G ra y @ m ic ro s o ft.c o m
RESULT:= OWNERS[name,email] ∩ BUYERS[name,email]
Relational Algebra
6
Fall 2001 Database Systems 11
Projection
• Find all the items on which at least one bid was placed
 ¢¡¤£¦¥¨§© 


!
#
RESULT := BIDS[iid]
Fall 2001 Database Systems 12
Selection
• Select certain tuples from a relation R based on a boolean
condition C
– written as R where C or
– meaning:
RCσ
for each tuple t in R
if t makes C true then
return t in the resulting relation
end-for
Relational Algebra
7
Fall 2001 Database Systems 13
Selection
• The selection condition C is built of
– atomic conditions of the form Ai ∝ Aj or Ai ∝ c where
• Ai, Aj are attributes and c is a constant of the same domain of
values, and
• ∝ is a comparison predicate of the form: =,  ,  , = , = , etc.
• If C1, C2 are selection conditions, then so are
• C1 AND C2
• C1 OR C2
• NOT C1
Fall 2001 Database Systems 14
Selection
• Find the bid identifiers of bids for item number “I1”:
 ¢¡¤£¦¥¨§© 
 !
 $#
 ¤%
I1-BIDS := BIDS WHERE iid = “I1”
RESULT := I1-BIDS[bid]
Relational Algebra
8
Fall 2001 Database Systems 15
Selection
• Find the bid identifiers of bids for item number “I1” that are
strictly more than $15.
I1-BIDS := BIDS WHERE
iid = “I1” AND amount  15
RESULT := I1-BIDS[bid]
 ¢¡¤£¦¥¨§© 
!
#
Fall 2001 Database Systems 16
Selection
• Find the dates in which a bid for item number “I1” or
“I5” was placed
I1orI5-BIDS := BIDS WHERE
iid = “I1” OR iid = “i5”
RESULT := I1orI5-BIDS[date]
$%('#)¤021 3542687
9A@2BDC
9A@2BFE
G(@HE
Relational Algebra
9
Fall 2001 Database Systems 17
Cartesian Product
• Multiply the relations R and S, producing |R|x|S| many
tuples with attributes head(R)+head(S)
• Cartesian product combines two relations into one “big”
relation
• meaning
for each tuple r in R do
for each tuple s in S do
compute a new tuple containing
all attributes in r and s
end-for
end-for
Fall 2001 Database Systems 18
R := Bids WHERE Amount  20 T := Items WHERE oid=“O2”
S := T[iid,name]
P := R X S
  ¡£¢ ¤ ¥§¦©¨ ¢ ¤ ¡¤ !#©$¨
% '( )0213 465 %7 8£7
% '5 9@0A 47 %7 BC7
% '@8 9@02( 465 %5 B3
D EF G HPIQSR
T@U VXW Y2YW `badc£W egf
h@i p£q£r qstuY6q
v w§x€y‚ ƒ w§x „£…†b‡ w§x ˆ ƒ w‰x€y2g‘2ˆ6ƒ w§x ’§“X”•–† —Sx ˆ ƒ —Sx ˜#…©“X‡
™d e@f g2h6i6j kl ™m n‚m k2f oCd pp©d qgr
™d ste
™d e©l u2h©v k2m ™m w@m k2f oCd pp©d qgr
™d ste
™d en u2h©f kl ™l wj k2f oCd pp©d qgr
™d ste
™d e@f g2h6i6j kl ™m n‚m k©i x‚y@zy©{b|–}2pgy
™d e©l u2h©v k2m ™m w@m k©i x‚y@zy©{b|–}2pgy
™d en u2h©f kl ™l wj k©i x‚y@zy©{b|–}2pgy
Relational Algebra
10
Fall 2001 Database Systems 19
Relational Algebra - Join
• For all pairs of tuples r and s from relations R and S where
Head(R)=A1…AnB1…Bk and Head(S)=B1…BkC1…Cm
such that r[B1…Bk] = s[B1…Bk],
include a tuple in R
 ¢¡ S with
attributes A1…AnB1…BkC1…Cm
• The attributes in common between the two relations (B1…Bk) are
called the “join attributes”
• The join is a cartesian product followed by a selection on the join
attributes, and a projection to remove the duplication of the join
attributes [formally: you have to rename the join attributes in one
relation so that you can express the selection/projection
operations]
Also called equijoin since
the main criteria is the
equality of join attributes
Fall 2001 Database Systems 20
Relational Algebra - Join
• Find all people with the same name and email address from the
“buyers” and “owners” relations
– join attributes are “Name” and “Email” from the buyer and
owners relations
– the joined relation will have attributes “Buyid, Name, Email, Oid”
– there are 5 × 4 pairs of tuples to compare on the attributes
“Name” and “Email”
£¥¤§¦©¨
¥  ¨¥
£!$#%' )(1032 ¨ 03( %54  %'
67 8@9BADC G r a y @ m ic ro s o ft,c o m E3F
Relational Algebra
11
Fall 2001 Database Systems 21
Relational Algebra - Join
 ¢¡¤£¦¥¢§¢¨  ¢©  Gray@microsoft,com
 !# $% Smith@aol.com
#')(10323
45 6¤798A@B Johns@geocities.com
4DC)E#F¢GIH
PDQ RASUTWVYX Brown@netmail.com `badcDegf3h
iqp r¤sUtvu Gray@microsoft.com
ixw€ybA‚¢ƒ
„¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com
„¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com
•¢–¤—¦˜¢™¢d •¢e fghi Gray@microsoft,com
Example below shows four of the twenty pairs of tuples
considered for the join
Fall 2001 Database Systems 22
Relational Algebra - Join
• Find the names of items with bids over $20
• Find the names of the owners of items with bids over $20
and are located in Boston
Temp1 := Bids WHERE Amount  20
Temp2 := Items jlk Temp1
Result := Temp2[Name]
Temp1 := Bids WHERE Amount  20
Temp3 := Items WHERE Location = “Boston”
Temp2 := Temp3 jlk Temp1
Temp4 := Temp2 jlk Owners
Result := Temp4[Owners.Name]
Relational Algebra
12
Fall 2001 Database Systems 23
Relational Algebra - Division
• Let head(R)=A1…AnB1…Bk and head(S)= B1…Bk
• R ÷ S is the “maximal” set of tuples from R[A1…An] such that
R contains all tuples in (R ÷ S) x S.
• Division is often
used for “for-all”
queries, e.g. “Find
tuples in R that are
in a relation with
‘all’ tuples in S.”
• All the attributes in the dividing relation S must exist in the
divided relation R!
for all tuples r in R[A1…An]
if for all tuples s in S, r+s is in R
place r in R ÷ S
end-if
end-for
Fall 2001 Database Systems 24
Relational Algebra - Division
  ¡ ¢ £
¤¦¥ §¨¥ ©¥
¤ §¨¥ ©¥
¤¦¥ § ©¥
¤¦¥ § ©
¤ §¨¥ ©
¤¦¥ § ©
¤¦¥ § ©
¤¦¥ §¨¥ ©
!
$#
$%
 ' (
)10 230
4 5 6
798 @38
7BA @38
Find:
• R ÷ S
• R ÷ V
• R ÷ Y
C DEGFIH¦PQSR TUR VXW
÷ S
Relational Algebra
13
Fall 2001 Database Systems 25
Relational Algebra - Division
  ¡ ¢ £
¤¦¥ §¨¥ ©¥
¤ §¨¥ ©¥
¤¦¥ § ©¥
¤¦¥ § ©
¤ §¨¥ ©
¤¦¥ § ©
¤¦¥ § ©
¤¦¥ §¨¥ ©
!
$#
$%
 ' (
)10 230
4 5 6
798 @38
7BA @38
Find:
• R ÷ S
• R ÷ V
• R ÷ Y
Fall 2001 Database Systems 26
Relational Algebra - Division
• Find identifiers of buyers who placed a bid on “all” the items
• Find the identifiers of items that have a bid from “all” the buyers
Temp := Items[Iid]
Temp1:= Bids[Buyid,Iid]
Result := Temp1 ÷ Temp
A := Buyers[BuyId]
B := Bids[Iid, BuyId]
Result := B ÷ A
Relational Algebra
14
Fall 2001 Database Systems 27
Relational Algebra Operations
– Union R ∪ S
– Intersection R ∩ S
– Difference R - S
– Assignment S(B1…Bn) := R(A1…An)
– Selection R where C
– Projection R[A1…An]
– Cartesian Product R x S
– Join R
 ¢¡ S
– Division R ÷ S
Fall 2001 Database Systems 28
£¥¤§¦¥¨© £¥ ¦  !!#
$¥% (')021 Smith@aol.com
$¥3 465718@9 Johns@geocities.com
$A BC@5EDF8 Brown@netmail.com
$ G H(CPIRQ Gray@microsoft.com
S!TFU(VWX SY2`bac d¥ef g Vfe!ah
ibp qsrut2v Gray@microsoft,com
iw xy7€7!r@‚Pƒ Robert432@aol.com
i„ …6y7†‡Pƒ Johns@somewhere.com
i7ˆ …6tRƒRy!‡ Jj@yahoo.com
i‰ (‘E’@ Duke@jazz.com “R”F•–— “˜™ de˜™ f
gEh(i j2kRl2g2m
˜
kon
p7q req sbtuuvwRx yEz@x@{Pz7|
p7} re} ~6€R€o|u
y‚„ƒ …
zo†PxP{Pz7|
pE‡ re} ˆ!wvwox2t@zR€@w ‰FwoŠ
‹zR‚@Œ
2Ž  ‘7’o“s”@•2–P– —!•˜˜•@–
E™ FŽ š› 2’Rœ2
ž’oŸR 7¡
›R¢£u•2–P–@’
¤!¥ •@¦P¦o˜¥
o§ e¨ ›R¢” ¥ © ’@–@¦P’7ª
«!¬­(® «b¯° ­(±E²@³ ¬!¯° «´2µ¬E° ¶s· ¸7´E¹2²
º»¼b½ ¾!¿7À7Á ½ ºÃ ½uÄ
º»¼bà ¾!¿7À7Á ÂRÅ ºÄ ÆÄ
º»¼À ¾!¿7À½ ½ º7Å ½„¾
º»¼Å Ç!¿½ ÂEÆ ºÄ ÈbÄ
º»¼Ä Ç!¿½ ½ ºÃ ÃEÁ
º»¼Æ Ç!¿Ã ÂRÅ º7Å È!Á
º»¼!È Ç!¿Ã Âà º½ Å
º»¼¾ Ç!¿7À Âà ºÀ Ä
Auction Database
Relational Algebra
15
Fall 2001 Database Systems 29
Problem 1
Find the name and email of owners of items located in
“Boston”
A := Items WHERE Location = “Boston”
B := A
 ¢¡ Owners
Result := B[Owners.Name, Owners.Email]
Fall 2001 Database Systems 30
Problem 2
Find the identifiers and amount of bids placed by
buyer “Roberts”
A := Buyers WHERE Name = “Roberts”
B := A
 ¢¡ Bids
Result := B[Bid, Amount]
Relational Algebra
16
Fall 2001 Database Systems 31
Problem 3
Find the names of buyers who placed a bid on an item
owned by “Brown”
A := Owners WHERE Name = “Brown”
B := (A
 ¢¡ Items) [Iid]
C := B
 ¢¡ Bids
Result := (C
 ¢¡ Buyers) [Buyers.Name]
Fall 2001 Database Systems 32
Problem 4
Find the identifier of items with more than one bid
A := Bids[Bid, Iid]
B := A x Bids[Bid,Iid]
C := B WHERE (A.Bid  Bids.Bid)
AND (A.Iid = Bids.Iid)
Result := C[Iid]
Relational Algebra
17
Fall 2001 Database Systems 33
Problem 5
Find the names of items all buyers placed a bid on
A := (Bids[Iid, BuyId]) ÷ (Buyers[Buyid])
B := A
 ¢¡ Items
Result := B[Name]

Weitere ähnliche Inhalte

Andere mochten auch

Tecnologo en gestión logística
Tecnologo en gestión logísticaTecnologo en gestión logística
Tecnologo en gestión logísticaElvia Padilla
 
Verbinding in de keten FFF2017
Verbinding in de keten FFF2017Verbinding in de keten FFF2017
Verbinding in de keten FFF2017TOPdesk
 
Extending the Yahoo Streaming Benchmark + MapR Benchmarks
Extending the Yahoo Streaming Benchmark + MapR BenchmarksExtending the Yahoo Streaming Benchmark + MapR Benchmarks
Extending the Yahoo Streaming Benchmark + MapR BenchmarksJamie Grier
 
Digestion biochemistry
Digestion biochemistryDigestion biochemistry
Digestion biochemistrysantusan
 
Mozilla at Darbar college
Mozilla at Darbar collegeMozilla at Darbar college
Mozilla at Darbar collegeShreyas Kutty
 

Andere mochten auch (7)

Tecnologo en gestión logística
Tecnologo en gestión logísticaTecnologo en gestión logística
Tecnologo en gestión logística
 
Verbinding in de keten FFF2017
Verbinding in de keten FFF2017Verbinding in de keten FFF2017
Verbinding in de keten FFF2017
 
Extending the Yahoo Streaming Benchmark + MapR Benchmarks
Extending the Yahoo Streaming Benchmark + MapR BenchmarksExtending the Yahoo Streaming Benchmark + MapR Benchmarks
Extending the Yahoo Streaming Benchmark + MapR Benchmarks
 
Digestion biochemistry
Digestion biochemistryDigestion biochemistry
Digestion biochemistry
 
Constitucion española
Constitucion española Constitucion española
Constitucion española
 
Mozilla at Darbar college
Mozilla at Darbar collegeMozilla at Darbar college
Mozilla at Darbar college
 
Manual en español syma x8 c venture
Manual en español  syma x8 c ventureManual en español  syma x8 c venture
Manual en español syma x8 c venture
 

Ähnlich wie [Www.pkbulk.blogspot.com]dbms04

Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational modelATS SBGI MIRAJ
 
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
Data Base Management system relation algebra ER diageam Sql Query -nested  qu...Data Base Management system relation algebra ER diageam Sql Query -nested  qu...
Data Base Management system relation algebra ER diageam Sql Query -nested qu...kudiyarc
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdfKavinilaa
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational AlgebraPyingkodi Maran
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational AlgebraAmin Omi
 
[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06AnusAhmad
 
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
 
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweqdbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweqwrushabhsirsat
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.pptImXaib
 
TDC2016SP - Trilha Frameworks JavaScript
TDC2016SP - Trilha Frameworks JavaScriptTDC2016SP - Trilha Frameworks JavaScript
TDC2016SP - Trilha Frameworks JavaScripttdc-globalcode
 

Ähnlich wie [Www.pkbulk.blogspot.com]dbms04 (20)

Lecture5
Lecture5Lecture5
Lecture5
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
Data Base Management system relation algebra ER diageam Sql Query -nested  qu...Data Base Management system relation algebra ER diageam Sql Query -nested  qu...
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
 
DDL,DML,1stNF
DDL,DML,1stNFDDL,DML,1stNF
DDL,DML,1stNF
 
sfdfds
sfdfdssfdfds
sfdfds
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf
 
Compilation
CompilationCompilation
Compilation
 
Relational Database and Relational Algebra
Relational Database and Relational AlgebraRelational Database and Relational Algebra
Relational Database and Relational Algebra
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06
 
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
 
Realtime Analytics
Realtime AnalyticsRealtime Analytics
Realtime Analytics
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweqdbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
dbms-unit-_part-1.pptxeqweqweqweqweqweqweqweq
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
R Algebra.ppt
R Algebra.pptR Algebra.ppt
R Algebra.ppt
 
14285 lecture2
14285 lecture214285 lecture2
14285 lecture2
 
TDC2016SP - Trilha Frameworks JavaScript
TDC2016SP - Trilha Frameworks JavaScriptTDC2016SP - Trilha Frameworks JavaScript
TDC2016SP - Trilha Frameworks JavaScript
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 

Mehr von AnusAhmad

[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexingAnusAhmad
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13AnusAhmad
 
9. java server faces
9. java server faces9. java server faces
9. java server facesAnusAhmad
 
8. java script
8. java script8. java script
8. java scriptAnusAhmad
 
2. http, html
2. http, html2. http, html
2. http, htmlAnusAhmad
 
6. hibernate
6. hibernate6. hibernate
6. hibernateAnusAhmad
 

Mehr von AnusAhmad (20)

[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
 
[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
 
[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05
 
[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03
 
[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02
 
[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
 
8. java script
8. java script8. java script
8. java script
 
7. struts
7. struts7. struts
7. struts
 
5. servlets
5. servlets5. servlets
5. servlets
 
4. jsp
4. jsp4. jsp
4. jsp
 
3. applets
3. applets3. applets
3. applets
 
2. http, html
2. http, html2. http, html
2. http, html
 
1. intro
1. intro1. intro
1. intro
 
6. hibernate
6. hibernate6. hibernate
6. hibernate
 

Kürzlich hochgeladen

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

[Www.pkbulk.blogspot.com]dbms04

  • 1. Relational Algebra 1 Fall 2001 Database Systems 1 Relational Algebra • A relation is a set of tuples. Each relational algebra operation takes as input a list of relations and produces a single relation. • General form: OperatorArguments (List of Relations)   New Relation • After each operation, the remaining attributes are carried to the new relation. The attributes may be renamed, but their domain remains the same. Fall 2001 Database Systems 2 Set Theoretic Operations • Regular set operations on relations • A set operation requires two participating relations R and S to be compatible – R and S should have the same attributes • R(Name:D1, Email:D2) • S(Name:D1, Email:D2, Address:D3) • T(Name:D1, Email:D4) • V(Name:D1, Email:D2) Which relations above are union (set operation) compatible? – Union compatibility may require type conversion (casting).
  • 2. Relational Algebra 2 Fall 2001 Database Systems 3 Set Operations  ¢¡¤£¦¥ §©¨£ ¥¡ ! #¤$%¥(')0¥$¡1$) 243©5 673 SR ∪ 8 9 @BADC7E F©GIHQP©RDHSR©T¤F F 5H QPUFVT 5 3 8 6 T 9 W 3 H¤FVTGQFVXYH 56 V3 SR ∩ 8 9 @BADC7E F©GIHQP©RDHSR©T¤F ` 6 HDP 5 3 8aR 3Yb 9 c 5d Qd FVT¤F 3 XQF SR − 8 9 @BADC7E F©GIHQP©RDHSR©T¤F 5 3 8e`¦AQH 36 H 5 3 9 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii Fall 2001 Database Systems 4 pYq¢rs0t%u pQvw r¤x€y¤ ‚yx0vƒ „Y… †(‡Yˆ‰  Smith@aol.com „Y‘ ’“€”€•—– Johns@geocities.com ˜™ d0e “gf)• Brown@netmail.com ˜h i1e j—k Gray@microsoft.com l0m)n)o0p0q l‚r s0tu vw‚xy o0x w0tz {%| })~  € Gray@microsoft,com {% ‚‚ƒ‚„g…‚~ † ‡ Robert432@aol.com {0ˆ ‰ƒgŠ‚‹—‡ Johns@somewhere.com {€Œ ‰—‡ ƒg‹ Jj@yahoo.com {0 Ž(g—… Duke@jazz.com‘g’¤“0”Q• ‘0–— ˜Q–— ™š‚›œ —–ž—Ÿ  g¡ œ ¢g£gž š€Ÿ—–£g¤ ¥%¦ §Y¦ ¨)© ª‚«¬‚­ ®€¯€­ ° ¯g± ¥%² §Y² ³1´µgµ€´± ¶U®%´· ¸ ¹ ¯gº—­ ° ¯€± ¥0» §Y² ¼¬%«¬‚­ © ¯gµ—¬ ½¤¬€¾¦¿¯€· À ¥€Á §» ‚¯gäµ—ª—­ ­ ³ª‚« «ª—­ Ä0Å ÆÇ ÈÉ Ê€Ëg̤͂ʂΗςРɀÑÒ Ó—Ô Ô Ê ÕÖ Ó—× ×—Ø Ö Ä0Ù ÆYÚ Æ¤Û€ÑË—ÜÝÉ€ÑÛ Ö Þ Ê€Ô × Êgß à‚áâ%ã à%äå â%æ€ç è á‚äå à0é—êgá€å ë1ì¤í—égî ç ï0ðñ%ò ó0ô—õ€ö ÷%ò ïø òù ï0ðñ%ø ó0ô—õ€ö ÷gú ï%ù û0ù ï0ðñ0õ ó0ô—õ%ò ÷%ò ï€ú òó ï0ðñgú ü%ôgò ÷0ù ï%ù ý%ù ï0ðñ0ù ü%ôgò ÷%ò ïø øgö ï0ðñ0û ü%ôgø ÷gú ï€ú ý‚ö ï0ðñ‚ý ü%ôgø ÷%ø ïò ú ï0ðñ0ó ü%ô—õ ÷%ø ï%õ ù
  • 3. Relational Algebra 3 Fall 2001 Database Systems 5 Assignment and Alias • Given a relation R, head(R)=A1…An is the list of attributes in R. • For each attribute, dom(A) gives the domain of A, name(A) gives the name of the attribute • Suppose B1…Bn is a list of attributes such that for each i, dom(Bi) = dom(Ai) Then assignment (:=) changes the names of some or all of the attributes in R and results in a new relation S, S(B1…Bn) := R(A1…An) and dom(B1) = dom(A1) … dom(Bn) = dom(An). Fall 2001 Database Systems 6 Set Operations • Find all people who are registered as buyers or owners  ¢¡¤£¦¥¨§© ! ! # $% ')(10 243 Smith@aol.com $65 798@3¤ACB Johns@geocities.com DE% F¦GIHCP Gray@microsoft.com QRQRQ QRQ@Q QRQRQ BUYERS-2(oid,name,email) := BUYERS(buyid,name,email) RESULT := BUYERS-2 ∪ OWNERS
  • 4. Relational Algebra 4 Fall 2001 Database Systems 7 Set Operations • Find all people who are owners but not buyers  ¢¡¤£¦¥¨§© ! !¤ # $% ')(0 132 Smith@aol.com $4 5768293@ Johns@geocities.com $¨A B¦CED3F Gray@microsoft.com G G G BUYERS-2(oid,name,email) := BUYERS(buyid,name,email) RESULT:= OWNERS - BUYERS-2 Fall 2001 Database Systems 8 Set Operations • Find all people who are both owners and buyers HPI7QSRUTV WYX ` acb7dUe e7dUbfXhg BUYERS-2(oid,name,email) := BUYERS(buyid,name,email) RESULT := OWNERS ∩ BUYERS-2
  • 5. Relational Algebra 5 Fall 2001 Database Systems 9 Projection • Select all tuples from relation R, restrict each tuple to the input attributes – written as R[A1…An] or for attributes A1…An from R – meaning nAA ...1 π for each tuple in R construct a new tuple containing only attributes A1…An place the new tuple in the result end-for remove duplicate tuples to preserve the set property Fall 2001 Database Systems 10 Projection • Find the names and email addresses of people who are both buyers and owners  ¢¡¤£¦¥¨§© !# $%('0) G ra y @ m ic ro s o ft.c o m RESULT:= OWNERS[name,email] ∩ BUYERS[name,email]
  • 6. Relational Algebra 6 Fall 2001 Database Systems 11 Projection • Find all the items on which at least one bid was placed  ¢¡¤£¦¥¨§© ! # RESULT := BIDS[iid] Fall 2001 Database Systems 12 Selection • Select certain tuples from a relation R based on a boolean condition C – written as R where C or – meaning: RCσ for each tuple t in R if t makes C true then return t in the resulting relation end-for
  • 7. Relational Algebra 7 Fall 2001 Database Systems 13 Selection • The selection condition C is built of – atomic conditions of the form Ai ∝ Aj or Ai ∝ c where • Ai, Aj are attributes and c is a constant of the same domain of values, and • ∝ is a comparison predicate of the form: =, , , = , = , etc. • If C1, C2 are selection conditions, then so are • C1 AND C2 • C1 OR C2 • NOT C1 Fall 2001 Database Systems 14 Selection • Find the bid identifiers of bids for item number “I1”:  ¢¡¤£¦¥¨§© ! $# ¤% I1-BIDS := BIDS WHERE iid = “I1” RESULT := I1-BIDS[bid]
  • 8. Relational Algebra 8 Fall 2001 Database Systems 15 Selection • Find the bid identifiers of bids for item number “I1” that are strictly more than $15. I1-BIDS := BIDS WHERE iid = “I1” AND amount 15 RESULT := I1-BIDS[bid]  ¢¡¤£¦¥¨§© ! # Fall 2001 Database Systems 16 Selection • Find the dates in which a bid for item number “I1” or “I5” was placed I1orI5-BIDS := BIDS WHERE iid = “I1” OR iid = “i5” RESULT := I1orI5-BIDS[date] $%('#)¤021 3542687 9A@2BDC 9A@2BFE G(@HE
  • 9. Relational Algebra 9 Fall 2001 Database Systems 17 Cartesian Product • Multiply the relations R and S, producing |R|x|S| many tuples with attributes head(R)+head(S) • Cartesian product combines two relations into one “big” relation • meaning for each tuple r in R do for each tuple s in S do compute a new tuple containing all attributes in r and s end-for end-for Fall 2001 Database Systems 18 R := Bids WHERE Amount 20 T := Items WHERE oid=“O2” S := T[iid,name] P := R X S   ¡£¢ ¤ ¥§¦©¨ ¢ ¤ ¡¤ !#©$¨ % '( )0213 465 %7 8£7 % '5 9@0A 47 %7 BC7 % '@8 9@02( 465 %5 B3 D EF G HPIQSR T@U VXW Y2YW `badc£W egf h@i p£q£r qstuY6q v w§x€y‚ ƒ w§x „£…†b‡ w§x ˆ ƒ w‰x€y2g‘2ˆ6ƒ w§x ’§“X”•–† —Sx ˆ ƒ —Sx ˜#…©“X‡ ™d e@f g2h6i6j kl ™m n‚m k2f oCd pp©d qgr ™d ste ™d e©l u2h©v k2m ™m w@m k2f oCd pp©d qgr ™d ste ™d en u2h©f kl ™l wj k2f oCd pp©d qgr ™d ste ™d e@f g2h6i6j kl ™m n‚m k©i x‚y@zy©{b|–}2pgy ™d e©l u2h©v k2m ™m w@m k©i x‚y@zy©{b|–}2pgy ™d en u2h©f kl ™l wj k©i x‚y@zy©{b|–}2pgy
  • 10. Relational Algebra 10 Fall 2001 Database Systems 19 Relational Algebra - Join • For all pairs of tuples r and s from relations R and S where Head(R)=A1…AnB1…Bk and Head(S)=B1…BkC1…Cm such that r[B1…Bk] = s[B1…Bk], include a tuple in R  ¢¡ S with attributes A1…AnB1…BkC1…Cm • The attributes in common between the two relations (B1…Bk) are called the “join attributes” • The join is a cartesian product followed by a selection on the join attributes, and a projection to remove the duplication of the join attributes [formally: you have to rename the join attributes in one relation so that you can express the selection/projection operations] Also called equijoin since the main criteria is the equality of join attributes Fall 2001 Database Systems 20 Relational Algebra - Join • Find all people with the same name and email address from the “buyers” and “owners” relations – join attributes are “Name” and “Email” from the buyer and owners relations – the joined relation will have attributes “Buyid, Name, Email, Oid” – there are 5 × 4 pairs of tuples to compare on the attributes “Name” and “Email” £¥¤§¦©¨ ¥ ¨¥ £!$#%' )(1032 ¨ 03( %54 %' 67 8@9BADC G r a y @ m ic ro s o ft,c o m E3F
  • 11. Relational Algebra 11 Fall 2001 Database Systems 21 Relational Algebra - Join  ¢¡¤£¦¥¢§¢¨  ¢© Gray@microsoft,com !# $% Smith@aol.com #')(10323 45 6¤798A@B Johns@geocities.com 4DC)E#F¢GIH PDQ RASUTWVYX Brown@netmail.com `badcDegf3h iqp r¤sUtvu Gray@microsoft.com ixw€ybA‚¢ƒ „¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com „¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com •¢–¤—¦˜¢™¢d •¢e fghi Gray@microsoft,com Example below shows four of the twenty pairs of tuples considered for the join Fall 2001 Database Systems 22 Relational Algebra - Join • Find the names of items with bids over $20 • Find the names of the owners of items with bids over $20 and are located in Boston Temp1 := Bids WHERE Amount 20 Temp2 := Items jlk Temp1 Result := Temp2[Name] Temp1 := Bids WHERE Amount 20 Temp3 := Items WHERE Location = “Boston” Temp2 := Temp3 jlk Temp1 Temp4 := Temp2 jlk Owners Result := Temp4[Owners.Name]
  • 12. Relational Algebra 12 Fall 2001 Database Systems 23 Relational Algebra - Division • Let head(R)=A1…AnB1…Bk and head(S)= B1…Bk • R ÷ S is the “maximal” set of tuples from R[A1…An] such that R contains all tuples in (R ÷ S) x S. • Division is often used for “for-all” queries, e.g. “Find tuples in R that are in a relation with ‘all’ tuples in S.” • All the attributes in the dividing relation S must exist in the divided relation R! for all tuples r in R[A1…An] if for all tuples s in S, r+s is in R place r in R ÷ S end-if end-for Fall 2001 Database Systems 24 Relational Algebra - Division   ¡ ¢ £ ¤¦¥ §¨¥ ©¥ ¤ §¨¥ ©¥ ¤¦¥ § ©¥ ¤¦¥ § © ¤ §¨¥ © ¤¦¥ § © ¤¦¥ § © ¤¦¥ §¨¥ © ! $# $% ' ( )10 230 4 5 6 798 @38 7BA @38 Find: • R ÷ S • R ÷ V • R ÷ Y C DEGFIH¦PQSR TUR VXW ÷ S
  • 13. Relational Algebra 13 Fall 2001 Database Systems 25 Relational Algebra - Division   ¡ ¢ £ ¤¦¥ §¨¥ ©¥ ¤ §¨¥ ©¥ ¤¦¥ § ©¥ ¤¦¥ § © ¤ §¨¥ © ¤¦¥ § © ¤¦¥ § © ¤¦¥ §¨¥ © ! $# $% ' ( )10 230 4 5 6 798 @38 7BA @38 Find: • R ÷ S • R ÷ V • R ÷ Y Fall 2001 Database Systems 26 Relational Algebra - Division • Find identifiers of buyers who placed a bid on “all” the items • Find the identifiers of items that have a bid from “all” the buyers Temp := Items[Iid] Temp1:= Bids[Buyid,Iid] Result := Temp1 ÷ Temp A := Buyers[BuyId] B := Bids[Iid, BuyId] Result := B ÷ A
  • 14. Relational Algebra 14 Fall 2001 Database Systems 27 Relational Algebra Operations – Union R ∪ S – Intersection R ∩ S – Difference R - S – Assignment S(B1…Bn) := R(A1…An) – Selection R where C – Projection R[A1…An] – Cartesian Product R x S – Join R  ¢¡ S – Division R ÷ S Fall 2001 Database Systems 28 £¥¤§¦¥¨© £¥ ¦ !!# $¥% (')021 Smith@aol.com $¥3 465718@9 Johns@geocities.com $A BC@5EDF8 Brown@netmail.com $ G H(CPIRQ Gray@microsoft.com S!TFU(VWX SY2`bac d¥ef g Vfe!ah ibp qsrut2v Gray@microsoft,com iw xy7€7!r@‚Pƒ Robert432@aol.com i„ …6y7†‡Pƒ Johns@somewhere.com i7ˆ …6tRƒRy!‡ Jj@yahoo.com i‰ (‘E’@ Duke@jazz.com “R”F•–— “˜™ de˜™ f gEh(i j2kRl2g2m ˜ kon p7q req sbtuuvwRx yEz@x@{Pz7| p7} re} ~6€R€o|u y‚„ƒ … zo†PxP{Pz7| pE‡ re} ˆ!wvwox2t@zR€@w ‰FwoŠ ‹zR‚@Œ 2Ž  ‘7’o“s”@•2–P– —!•˜˜•@– E™ FŽ š› 2’Rœ2 ž’oŸR 7¡ ›R¢£u•2–P–@’ ¤!¥ •@¦P¦o˜¥ o§ e¨ ›R¢” ¥ © ’@–@¦P’7ª «!¬­(® «b¯° ­(±E²@³ ¬!¯° «´2µ¬E° ¶s· ¸7´E¹2² º»¼b½ ¾!¿7À7Á ½ ºÃ ½uÄ º»¼bà ¾!¿7À7Á ÂRÅ ºÄ ÆÄ º»¼À ¾!¿7À½ ½ º7Å ½„¾ º»¼Å Ç!¿½ ÂEÆ ºÄ ÈbÄ º»¼Ä Ç!¿½ ½ ºÃ ÃEÁ º»¼Æ Ç!¿Ã ÂRÅ º7Å È!Á º»¼!È Ç!¿Ã Âà º½ Å º»¼¾ Ç!¿7À Âà ºÀ Ä Auction Database
  • 15. Relational Algebra 15 Fall 2001 Database Systems 29 Problem 1 Find the name and email of owners of items located in “Boston” A := Items WHERE Location = “Boston” B := A  ¢¡ Owners Result := B[Owners.Name, Owners.Email] Fall 2001 Database Systems 30 Problem 2 Find the identifiers and amount of bids placed by buyer “Roberts” A := Buyers WHERE Name = “Roberts” B := A  ¢¡ Bids Result := B[Bid, Amount]
  • 16. Relational Algebra 16 Fall 2001 Database Systems 31 Problem 3 Find the names of buyers who placed a bid on an item owned by “Brown” A := Owners WHERE Name = “Brown” B := (A  ¢¡ Items) [Iid] C := B  ¢¡ Bids Result := (C  ¢¡ Buyers) [Buyers.Name] Fall 2001 Database Systems 32 Problem 4 Find the identifier of items with more than one bid A := Bids[Bid, Iid] B := A x Bids[Bid,Iid] C := B WHERE (A.Bid Bids.Bid) AND (A.Iid = Bids.Iid) Result := C[Iid]
  • 17. Relational Algebra 17 Fall 2001 Database Systems 33 Problem 5 Find the names of items all buyers placed a bid on A := (Bids[Iid, BuyId]) ÷ (Buyers[Buyid]) B := A  ¢¡ Items Result := B[Name]