DOCX

advertisement
CMPT 354 –Database Systems I (Section D100)
Assignment #4
Instructor: Richard Frank (rfrank@sfu.ca)
TA: Ankit Gupta (aga53@sfu.ca)
Total Marks: 50 (5% of the Individual Assignments)
Due Date:
Oct 7, 14:30
For all questions, use the AdventureWorksLT database.
Question 1) [12 marks] Find the names of customers who have ordered all products in category
‘Helmets’. First, write the relational algebra using the basic operations (selection, projection,
Cartesian product, set-difference, union), then write the SQL code to perform the division. Hint, both
are covered in the slides.
Question 2) For each relational algebra expression below, answer the following questions:
1) What is the meaning of the query in English? [1 mark each]
2) Can it be modified to be more efficient? If so, what is the most optimal solution? Rationalize
each step in terms of the number of tuples at each step, number of cells, etc. Show work/logic!
It is not necessary to go into the database and use exact numbers, just assume/estimate. [3
marks for algebra manipulation, 3 for rationalization]
a) πœ‹π‘ƒπ‘Ÿπ‘œπ‘‘π‘’π‘π‘‘.π‘π‘Žπ‘šπ‘’,πΆπ‘œπ‘™π‘œπ‘Ÿ [πœŽπ‘€π‘’π‘–π‘”β„Žπ‘‘<10 (π‘ƒπ‘Ÿπ‘œπ‘‘π‘’π‘π‘‘πΆπ‘Žπ‘‘π‘’π‘”π‘œπ‘Ÿπ‘¦ ⊳⊲ π‘ƒπ‘Ÿπ‘œπ‘‘π‘’π‘π‘‘)]
b) πœŽπ΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ 1.𝐢𝑖𝑑𝑦=′ π΅π‘’π‘Ÿπ‘›π‘Žπ‘π‘¦ ′ 𝐴𝑁𝐷 π‘†π‘’π‘π‘‡π‘œπ‘‘π‘Žπ‘™>1000 (πΆπ‘’π‘ π‘‘π‘œπ‘šπ‘’π‘Ÿ ⊳⊲ π‘†π‘Žπ‘™π‘’π‘ π‘‚π‘Ÿπ‘‘π‘’π‘Ÿπ»π‘’π‘Žπ‘‘π‘’π‘Ÿ
βŠ³βŠ²π‘†π‘Žπ‘™π‘’π‘ π‘‚π‘Ÿπ‘‘π‘’π‘Ÿπ»π‘’π‘Žπ‘‘π‘’π‘Ÿ.π‘†β„Žπ‘–π‘π‘‡π‘œπ΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ πΌπ·=π΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ πΌπ· (πœŒπ΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ 1 π΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ )
βŠ³βŠ²π‘†π‘Žπ‘™π‘’π‘ π‘‚π‘Ÿπ‘‘π‘’π‘Ÿπ»π‘’π‘Žπ‘‘π‘’π‘Ÿ.π΅π‘–π‘™π‘™π‘‡π‘œπ΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ πΌπ·=π΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ πΌπ· π΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ )
c) πœ‹πΉπ‘–π‘Ÿπ‘ π‘‘π‘›π‘Žπ‘šπ‘’ (πΆπ‘’π‘ π‘‘π‘œπ‘šπ‘’π‘Ÿ ⊳⊲ πΆπ‘’π‘ π‘‘π‘œπ‘šπ‘’π‘Ÿπ΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘  ⊳⊲ πœŽπΆπ‘–π‘‘π‘¦=′ π΅π‘’π‘Ÿπ‘›π‘Žπ‘π‘¦ ′ π΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ ) ∪
πœ‹πΉπ‘–π‘Ÿπ‘ π‘‘π‘›π‘Žπ‘šπ‘’ (πœŽπΏπ‘Žπ‘ π‘‘π‘π‘Žπ‘šπ‘’=′ π‘†π‘šπ‘–π‘‘β„Ž′ πΆπ‘’π‘ π‘‘π‘œπ‘šπ‘’π‘Ÿ ⊳⊲ πΆπ‘’π‘ π‘‘π‘œπ‘šπ‘’π‘Ÿπ΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘  ⊳⊲ πœŽπΆπ‘–π‘‘π‘¦=′ π‘‰π‘Žπ‘›π‘π‘œπ‘’π‘£π‘’π‘Ÿ ′ π΄π‘‘π‘‘π‘Ÿπ‘’π‘ π‘ )
d) πœŒπ‘‡π‘’π‘šπ‘ (πΆπ‘’π‘ π‘‘π‘œπ‘šπ‘’π‘Ÿ ⊳⊲ π‘†π‘Žπ‘™π‘’π‘ π‘‚π‘Ÿπ‘‘π‘’π‘Ÿπ»π‘’π‘Žπ‘‘π‘’π‘Ÿ ⊳⊲ π‘†π‘Žπ‘™π‘’π‘ π‘‚π‘Ÿπ‘‘π‘’π‘Ÿπ·π‘’π‘‘π‘Žπ‘–π‘™ ⊳⊲ π‘ƒπ‘Ÿπ‘œπ‘‘π‘’π‘π‘‘)
πœ‹πΉπ‘–π‘Ÿπ‘ π‘‘π‘›π‘Žπ‘šπ‘’,πΏπ‘Žπ‘ π‘‘π‘π‘Žπ‘šπ‘’,π‘ƒπ‘Ÿπ‘œπ‘‘π‘’π‘π‘‘.π‘π‘Žπ‘šπ‘’,πΏπ‘–π‘ π‘‘π‘ƒπ‘Ÿπ‘–π‘π‘’ (π‘‡π‘’π‘šπ‘)
Page 1
CMPT 354 –Database Systems I (Section D100)
Question 3) Write the optimal relational algebra statement for the following. [5 marks each]
a) Display the product descriptions for Mountain Tires (a product).
b) Assume the ProductCategory has 3 levels. Write the query to display the product names at all
levels within the hierarchy.
For example, assume ProductCategory looks like:
ProductCategoryID
1
2
3
4
ParentProductCategoryID
1
2
2
Name
Car
Sports
Mustang
Ferrari
Required result:
Car
Car
Sports
Sports
Mustang
Ferrari
Page 2
Download