{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

445-hw3-solutions

# 445-hw3-solutions - CMPSCI 445 Homework 3 SOLUTIONS 100...

This preview shows pages 1–2. Sign up to view the full content.

CMPSCI 445 — Homework 3 SOLUTIONS 100 Points Due October 1st, 5pm. Typed solutions preferred. If hand-written, solutions must be legible . 1. (30 pts) More on SQL Consider a database consisting of these three tables: Suppliers(sid: integer , sname: varchar(50), address: varchar(60)) Parts(pid: integer , pname: varchar(50), color: varchar(20)) Catalog(sid: integer, pid: integer , cost: real) Please answer the following questions, referring to this schema and the sample data shown in Figure 1. (a) Write an SQL query to find the distinct sids of suppliers who supply only red parts. Answer: SELECT DISTINCT C.sid FROM Catalog C WHERE NOT EXISTS ( SELECT * FROM Parts P WHERE P.pid = C.pid AND P.color <> Red ) (b) For the following SQL query: (i) write an English sentence describing the relation it computes, and (ii) show the result of the query on the sample data in Fig. 1 SELECT S.sname FROM Suppliers S WHERE NOT EXISTS ( ( SELECT P.pid FROM Parts P WHERE P.color = Red ) EXCEPT ( SELECT C.pid FROM Catalog C, Parts P WHERE C.sid = S.sid AND C.pid = P.pid AND P.color = Red )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern