Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following schema ( primary key fields are underlined ) : Customers ( cid , cname, city ) - cid is the unique identifier

Consider the following schema (primary key fields are underlined):
Customers (cid, cname, city)
-cid is the unique identifier for the customer
-cname is the name of the customer
-city is the city where customer resides
-cid is the primary key.
Suppliers (sid, sname, city)
-sid is the unique identifier for the supplier
-sname is suppliers name
-city is the city supplier is located
-sid is the primary key
Parts (pid, pname, color)
-pid is the unique identifier for the part
-pname is the parts name
-color is parts color
-pid is the primary key.
Catalog (pid, sid,price) : tuples in the Catalog table correspond to a catalogentries: i.e., parts and their suppliers.
-pid is the id of the part in the catalog entry
-sid is id of the supplier that supplies the part in the catalog
-price is the cost of the part in the catalog
-(sid,pid) is the primary key
-sid is a foreign key referencing Suppliers(sid)
-pid is a foreign key referencing Parts(pid)
Orders (cid,pid, sid, qty) : each tuple in Orders corresponds to an order. Assume each customer orders a particular part from a supplier once.
-cid is the customer that buys the part
-pid is the part sold
-sid is the supplier that supplies the part
-qty is the number of parts sold in a particular order
-(cid,sid, pid) is the primary key.
-(sid,pid) is a foreign key referencing Catalog (sid,pid)
Based on the above database schema, express the following queries in relational algebra. Assume set semantics for all operations.
1. Find all distinct parts supplied by Pullman stores. Return pids of those parts.
2. Find the suppliers in Pullman who supply a yellow part for less than $11. Return sids and names for those suppliers.
3. Find all parts which are provided by some supplier (i.e., they appear in the catalog) but they were never ordered by a customer. Return the pids and names of those parts.
4. Find all customers who ordered one of the products that Andy ordered. Return names and cities of those customers and the pids of the products they ordered.
5. Find the suppliers who have received orders from customers who live in the city where that supplier is located. Return sids, names, and cities of those suppliers.
6. Find customers who ordered more than 2 items from a single supplier (i.e., sum of the quantities of all parts customer purchased from the supplier is at least 3). Return names of the customers,sids of the suppliers, and number of items they ordered.
7. Find the customer cids who paid more than $20 on green parts.
8. Find the parts which are supplied by at least 3 different suppliers. Return the pids, names, and colors of those parts.
9. For each part in the catalog find the supplier that offers the lowest price; give the part name, supplier sid and the price supplier sells the part for.
10. Find the number of suppliers in each city.
The same data is also available in appendix A. In the tool, you can try the queries and check the output. The expected output for each relational algebra expression is provide in appendix B.
APPENDIX-A
Customers:
cidcnamecity
c1JohnPullman
c2AlliPullman
c3KellyMoscow
c4TomSpokane
c5SamSpokane
c6AndyPullman
Suppliers:
sidsnamecity
s1Best ToolsPullman
s2Pullman ToolsPullman
s3Acme ToolsMoscow
s4Parts & MorePullman
s5Supply StoreSpokane
s6Spokane HW StoreSpokane
Parts:
pidpnamecolor
p1Part1red
p2Part2red
p3Part3green
p4Part4green
p5Part5yellow
p6Part6red
P7Part7red
Catalog:
pidsidprice
p1s2$48
p1s3$51
p1s4$52
p1s6$49
p2s1$21
p2s2$20
p3s4$15
p5s1$10
p5s2$12
p5s3$9
p5s4$10
p5s6$11
p7s3$33
p7s4$35
Orders:
cidpidsidqty
c1p1s23
c1p3s41
c3p2s21
c3p3s42
c3p5s31
c3p5s22
c4p1s33
c4p2s24
c4p3s41
c6p3s41
c6p5s32
c6p5s63
c6p2s23
APPENDIX-B
1.
Catalog.pid
p1
p2
p3
p5
p7
2.
Catalog.sid Suppliers.sname
s1 BestTools
s4 Parts and More
3.
Parts.pid Parts.pname
p7 Part7
4.
Customers.cname Customers.city Orders.pid
John Pullman p3
Kelly Moscow p2
Kelly Moscow p3
Kelly Moscow p5
Tom Spokane p2
Tom Spokane p3
Andy Pullman p3
Andy Pullman p5
Andy Pullman p2
5.
Orders.sid Suppliers.sname Customers.city
s2 Pullman Tools Pullman
s4 Parts and More Pullman
s3 Acme Tools Moscow
6.
Customers.cname Orders.sid numItems
John s23
Kelly s23
Tom s33
Tom s24
Andy s63
Andy s23
7.
Orders.cid
c3
8.
Parts.pid; Parts.pname; Parts.color
p1; Part1; red
p5; Part5; yellow
9.
Parts.pname; Catalog.sid2; Catalog.price2
Part1; s2; 48
Part2; s2; 20
Part3; s4; 15
Part5; s3; 9
Part7; s3; 33
10.
Suppliers.city; numSupplier
Pullman; 3
Moscow; 1
Spokane; 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions