ch6 part9

advertisement
Session 3
Welcome: To session 3 - the 7th. learning sequence
“Relational algebra “
Recap : In the previous learning sequences, we
discussed some operators of relational algebra.
Present learning: We shall explore the following topic:
- Example Queries
1
Relational Algebra
2
Relational Algebra
A basic expression in the
relational algebra consists of
either one of the following:
 A relation in the database
 A constant relation
Relational Instances for the
Purchasing System
The Supplier relation:
S-number
S-name
S-city
S100
Ahmed
Amman
S200
Ali
Jarash
S300
Kasim
Irbid
S400
Jasim
Aquaba
S500
Rana
Amman
The Part relation:
P-number P-name Color
Price
P-city
P1
TV
Silver
300
Amman
P2
Camera
Black
100
Jarash
P3
Video
Black
200
Amman
P4
PC
Silver
400
Irbid
P5
Printer
Red
100
Irbid
P6
Scanner
silver
150
Jarash
5
The shipment relation:
S-number
S100
S100
S100
P-number
P1
P2
P3
Quantity
100
150
200
S100
S100
S100
P4
P5
P6
160
50
70
S200
S200
P1
P2
200
150
S300
P2
400
S400
S400
S500
P2
P4
P4
150
80
100
6
Example Queries
 S-city (Supplier)
 Q1- Find The cities for all suppliers .
Example Queries
 Q1- Find The cities for all suppliers .
 S-city (Supplier)
The result relation
S-city
Amman
Jarash
Irbid
Aquaba
Q2- Find city for Ahmed.
Example Queries
Example Queries
Q2- Find city for Ahmed.
Temp1   S-name = ‘Ahmed’ (Supplier)
Q2- Find city for Ahmed.
Example Queries
Temp1   S-name = ‘Ahmed’ (Supplier)
S-number
Temp1
S100
S-name
Ahmed
S-city
Amman
Example Queries
Q2- Find city for Ahmed.
Temp1   S-name = ‘Ahmed’ (Supplier)
S-number
Temp1
S100
Result   S-city (Temp1)
Result
S-city
Amman
S-name
Ahmed
S-city
Amman
Example Queries
 Q3- Find Supplier number and name for suppliers in
Amman.
Example Queries
 Q3- Find Supplier number and name for suppliers in
Amman.
Temp1   S-city= ‘Amman’ (Supplier)
Example Queries
 Q3- Find Supplier number and name for suppliers in
Amman.
Temp1   S-city= ‘Amman’ (Supplier)
Temp1
S-number S-name S-city
S100
Ahmed
Amman
S500
Rana
Amman
Example Queries
 Q3- Find Supplier number and name for suppliers in
Amman.
Temp1   S-city= ‘Amman’ (Supplier)
Temp1
S-number S-name S-city
S100
Ahmed
Amman
S500
Rana
Amman
Result   S-number, S-name (Temp1)
Example Queries
 Q3- Find Supplier number and name for suppliers in
Amman.
Temp1   S-city= ‘Amman’ (Supplier)
Temp1
S-number S-name S-city
S100
Ahmed
Amman
S500
Rana
Amman
Result   S-number, S-name (Temp1)
Result
S-number
S-name
S100
Ahmed
S500
Rana
 Q4- For each part supplied, find the part names and
the names of all cities storing these parts.
Example
Queries
the names of all cities storing these parts.
 Q4- For each part supplied, find the part names and
Temp1   P-number ( Shipment )
Example
Queries
the names of all cities storing these parts.
 Q4- For each part supplied, find the part names and
Temp1   P-number ( Shipment )
Temp1
P-number
P1
P2
P3
P4
P5
P6
Example
Queries
the names of all cities storing these parts.
 Q4- For each part supplied, find the part names and
Temp1   P-number ( Shipment )
Temp2  Part
Temp1
Example
Queries
the names of all cities storing these parts.
 Q4- For each part supplied, find the part names and
Temp1   P-number ( Shipment )
Temp2  Part
Temp1
Temp2
P-number P-name Color
P1
TV
Silver
Price
300
P-city
Amman
P2
Camera
Black
100
Jarash
P3
Video
Black
200
Amman
P4
PC
Silver
400
Irbid
P5
Printer
Red
100
Irbid
P6
Scanner silver
150
Jarash
Example
Queries
the names of all cities storing these parts.
 Q4- For each part supplied, find the part names and
Temp1   P-number ( Shipment )
Temp2  Part
Temp1
Result   P-name, p-city(Temp2)
P-name
Result
P-city
TV
Amman
Camera
Jarash
Video
Amman
PC
Irbid
Printer
Irbid
Scanner
Jarash
 Q5- For each part supplied, find the part numbers and
names of all cities supplying the parts.
Example
Queries
names of all cities supplying the parts.
 Q5- For each part supplied, find the part numbers and
Temp1  Shipment
Supplier
Example
Queries
names of all cities supplying the parts.
 Q5- For each part supplied, find the part numbers and
Temp1  Shipment
Supplier
Temp1
S-number
P-number
Quantity S-name S-city
S100
P1
100
Ahmed
Amman
S100
P2
150
Ahmed
Amman
S100
P3
200
Ahmed
Amman
S100
P4
160
Ahmed
Amman
S100
P5
50
Ahmed
Amman
S100
P6
70
Ahmed
Amman
S200
P1
200
Ali
Jarash
S200
P2
150
Ali
Jarash
S300
P2
400
Kasim
Irbid
S400
P2
150
Jasim
Aquaba
S400
P4
80
Jasim
Aquaba
Example
Queries
names of all cities supplying the parts.
 Q5- For each part supplied, find the part numbers and
Temp1  Shipment
Supplier
Result   P-number, S-city ( Temp1 )
Result
P-number S-city
P1
Amman
P2
Amman
P3
Amman
P4
Amman
P5
Amman
P6
Amman
P1
Jarash
P2
Jarash
P2
Irbid
P2
Aquaba
P4
Aquaba
P4
Amman
 Q6- Get supplier numbers for suppliers who supply
part p2
Example Queries
 Q6- Get supplier numbers for suppliers who supply
part p2
Temp1   p-number = ‘p2’ (Shipment)
Example Queries
 Q6- Get supplier numbers for suppliers who supply
part p2
Temp1   p-number = ‘p2’ (Shipment)
Temp1
S-number
P-number
Quantity
S100
S200
P2
P2
150
150
S300
S400
P2
P2
400
150
Example Queries
 Q6- Get supplier numbers for suppliers who supply
part p2
Temp1   P-number = ‘p2’ (Shipment)
Result   S-number ( Temp1 )
Result
S-number
S100
S200
S300
S400
Relational Algebra
Summary: In this learning sequence, we discussed some
example queries about purchasing system.
32
END
33
Download