Questions
Questions

MISM3403.16575.202610 Exam 2

Essay

Consider the following schema: #Suppliers(sid: integer, sname: string, address: string) #Parts(pid: integer, pname: string, color: string) #Makers(mid: integer, mname: string) #Catalog(sid: integer, pid: integer, mid integer,cost: integer) It is created using following CREATE TABLE Suppliers ( sid integer NOT NULL, sname varchar (25) NOT NULL, address varchar (25), PRIMARY KEY (sid) ); CREATE TABLE Parts ( pid integer NOT NULL, pname varchar (25) NOT NULL, color varchar (25) NOT NULL, PRIMARY KEY (pid) ); CREATE TABLE Makers ( mid integer NOT NULL, mname varchar (25) NOT NULL, PRIMARY KEY (mid) ); CREATE TABLE Catalog ( sid integer NOT NULL, pid integer NOT NULL,mid integer NOT NULL, cost integer, PRIMARY KEY (sid,pid,mid),  FOREIGN KEY (sid) REFERENCES Suppliers(sid), FOREIGN KEY (pid) REFERENCES Parts(pid), FOREIGN KEY (mid) REFERENCES Makers(mid) );   Here sid is the primary key for Suppliers, pid is the primary key for Parts, and (sid, pid, mid) together form the primary key for Catalog. The Catalog relation lists the prices charged for parts. Parts.color can take values "Red", "Blue", "Yellow" etc. Write one SQL query  to find the sids of suppliers who supply all color "Red" parts in the table Parts. Please type your answer.  

View Explanation

View Explanation

Verified Answer
Please login to view
Step-by-Step Analysis
The task is to identify suppliers that supply all parts whose color is Red. The provided SQL uses a classic NOT EXISTS pattern to express this universal-quantification requirement. First, the outer query selects sid from Suppliers (aliased as S). The WHERE clause uses NOT EXISTS with a correlated subquery involving Parts (aliased P) and Catalog (aliased C). Explanation of the logic step by step: - The inner subquery: SELECT P.pid FROM Parts P WHERE P.color = 'Red' AND NOT EXISTS (SELECT * FROM Catalog C WHERE C.sid = S.sid AND C.pid = P.pid) This subquery looks at every part P that......Login to view full explanation

Log in for full answers

We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!

More Practical Tools for Students Powered by AI Study Helper

Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!