Find the sids of suppliers who supply only red parts


Asked by admin @ in Engineering viewed by 268 People


Suppliers(sid: integer, sname: string, address: string)

Parts(pid: integer, pname: string, color: string)
Catalog(sid: integer, pid: integer, cost: real)
The Catalog relation lists the prices charged for parts by Suppliers.
Write the SQL script to create the tables, including implied foreign keys, and populate it with sample data. Sample data should be minimum 4 records each and able to prove the queries in part B are accurate.

Answered by admin @



Answer:

Explanation:

(a) Find the names of suppliers who supply some yellow part.

RA: sname(Suppliers on (color=0yellow0(Parts) on Catalog))

SQL:

SELECT S.sname

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.color =’yellow’

(b) Find the sids of suppliers who supply some green part but not ared part.

RA: sid(Suppliers on (color=0green0(Parts) on Catalog))−

sid(Suppliers on (color=0red0(Parts) on Catalog))

SQL:

SELECT S.sid

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.color =’green’

EXCEPT

SELECT T.sid

FROM Suppliers T, Parts P, Catalog C

WHERE T.sid = C.sid AND P.pid = C.pid AND P.color =’red’

(c) Find the sids and snames of suppliers who supply a’bolt’ whose price is under 100

dollars or whose color is red.

There is ambiguity here too. Some of you may interpret the questionto mean a bolt

whose price is under 100 dollars or a bolt whose color is red. Someof you may interpret

it to mean a bolt whose price is under 100 dollars or a red part. Ihave given points to

both these versions.

RA: sid,sname(Suppliers on((pname=0bolt0^cost<100)_(color=0red0)(Parts onCatalog)))

RA: sid,sname(Suppliers on((pname=0bolt0^(cost<100_color=0red0))(Parts onCatalog)))

SQL:

SELECT S.sid, S.sname

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.pname =’bolt’ AND C.cost < 100

UNION

SELECT T.sid, T.sname

FROM Suppliers T, Parts P, Catalog C

WHERE T.sid = C.sid AND P.pid = C.pid AND P.color =’red’

SELECT S.sid, S.sname

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.pname =’bolt’ AND C.cost < 100

UNION

SELECT T.sid, T.sname

FROM Suppliers T, Parts P, Catalog C

WHERE T.sid = C.sid AND P.pid = C.pid AND P.pname =’bolt’ AND P.color = ’red’

(d) Find the sids of suppliers who supply all parts.

RA: sid((sid,pid(Catalog))/(pid(Parts))

SQL:

SELECT C.sid

FROM Catalog C

WHERE NOT EXISTS (( SELECT P.pid

FROM Parts P )

EXCEPT

(SELECT C1.pid

FROM Catalog C1

WHERE C1.sid = C.sid ))

(e) Find pids of parts supplied by at least two differentsuppliers

RA: (CatPairs(1 !sid1, 2 !pid1, 3 !cost1, 4 !sid2, 5 !pid2, 6!cost2), Catalog×

Catalog)

pid1((pid1=pid2)^(sid16=sid2)CatPairs)

SQL:

SELECT P.pid

FROM Catalog P, Catalog C

WHERE P.pid = C.pid AND P.sid <> C.sid

(f) Find the names of suppliers who supply some brown part.

RA: sname(Suppliers on (color=0brown0(Parts) on Catalog))

SQL:

SELECT S.sname

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.color =’brown’

(g) Find the sids of suppliers who supply some yellow part but nota red part.

RA: sid(Suppliers on (color=0yellow0(Parts) on Catalog))−

sid(Suppliers on (color=0red0(Parts) on Catalog))

SQL:

SELECT S.sid

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.color =’yellow’

EXCEPT

SELECT T.sid

FROM Suppliers T, Parts P, Catalog C

WHERE T.sid = C.sid AND P.pid = C.pid AND P.color =’red’

(h) Find the sids and snames of suppliers who supply a’nut’ whose price is under 10 dollars

or whose color is pink.

There is ambiguity here too. Some of you interpret the question asa nut whose price is

under 10 dollars or a nut whose color is pink. Some of youinterpret it as a nut whose

price is under 10 dollars and a part whose color is pink. Bothversions are treated as

correct answers.

RA: sid,sname(Suppliers on((pname=0nut0^cost<10)_(color=0pink0)(Parts onCatalog)))

RA: sid,sname(Suppliers on((pname=0nut0^(cost<10_color=0pink0))(Parts onCatalog)))

SQL:

SELECT S.sid, S.sname

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.pname =’nut’ AND C.cost < 10

UNION

SELECT T.sid, T.sname

FROM Suppliers T, Parts P, Catalog C

WHERE T.sid = C.sid AND P.pid = C.pid AND P.color =’pink’

SELECT S.sid, S.sname

FROM Suppliers S, Parts P, Catalog C

WHERE S.sid = C.sid AND P.pid = C.pid AND P.pname =’nut’ AND C.cost < 10

UNION

SELECT T.sid, T.sname

FROM Suppliers T, Parts P, Catalog C

WHERE T.sid = C.sid AND P.pid = C.pid AND P.pname =’nut’ AND P.color = ’pink


Similar Questions

Where can you find these red-colored wetlands?

Asked by maham237 @ in Geography viewed by 330 persons

Which part of the eye contains vessels which supply blood

Asked by admin @ in Biology viewed by 291 persons

The layer of the wall of the eye that contains blood vessels that supply nutrients to the sheet of photoreceptors at the back of the eye and becomes the iris …

Major part of the agricultural credit is supplied by

Asked by admin @ in Business Studies viewed by 257 persons

1.Major part of the agricultural credit is supplied by​

Finding the real and imaginary parts of a complex number

Asked by admin @ in Mathematics viewed by 245 persons

What are the real and imaginary parts of the complex number? −6+2i Enter your answers in the boxes. (Can someone help me with this one?) The real part: The imaginary …

Find the sum or difference of the following fractional parts

Asked by admin @ in Math viewed by 422 persons

EVALUATE A.Find the sum or difference of the following fractional parts.1 1.2.3.4.​

Overcoming fixed mindset: a step-by-step guide to cultivating a growth mindset

Asked by wiki @ in Health viewed by 1263 persons

Which of the following would best complete this list?

Asked by wiki @ in Social Studies viewed by 728 persons

What had the king decided to do before he saw the spider

Asked by vanshika149 @ in English viewed by 1121 persons

Describe the karez in your own words

Asked by rajesh064 @ in English viewed by 1286 persons

What is 8 + (x + 5)?

Asked by jaylord7 @ in Mathematics viewed by 1079 persons

What is the topic of the info grapher

Asked by jesus643 @ in History viewed by 1375 persons

Elephant kills 11 in nepal , woman rescued from a friendly dolphine

Asked by kavin044 @ in English viewed by 1251 persons

Most viewed questions in Engineering


The word choice in the passage creates a mood of

Asked by maham237 @ in Engineering viewed by 829 persons


Batteries are used to power radios watches and cell phones

Asked by maham237 @ in Engineering viewed by 722 persons


According to the navigation rules which of the following is true

Asked by maham237 @ in Engineering viewed by 686 persons



You are approaching an intersection on a multiple lane road

Asked by admin @ in Engineering viewed by 670 persons



What is rectangular beam

Asked by maham237 @ in Engineering viewed by 646 persons


Interatomic separation

Asked by maham237 @ in Engineering viewed by 643 persons


230 volt hair dryer

Asked by maham237 @ in Engineering viewed by 641 persons



One pound mass of water fills a 2.4264

Asked by maham237 @ in Engineering viewed by 597 persons



For alloys of two hypothetical metals a and b

Asked by maham237 @ in Engineering viewed by 551 persons


Diameter pan

Asked by maham237 @ in Engineering viewed by 528 persons


Which sentence describes an advantage of writing

Asked by maham237 @ in Engineering viewed by 521 persons