- Information
- AI Chat
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.
Was this document helpful?
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.
Assignment 2-Solutions
Course: Advanced Database Systems (CS 434)
10 Documents
Students shared 10 documents in this course
University: New Jersey Institute of Technology
Was this document helpful?
This is a preview
Do you want full access? Go Premium and unlock all 7 pages
Access to all documents
Get Unlimited Downloads
Improve your grades
Already Premium?
CS 631: DATA MANAGEMENT SYSTEMS DESIGN
ASSIGNMENT 2
EXERCISE 1 (SQL Queries)
Consider the following schema:
SUPPLIERS (SID : integer, SNAME : string, CITY : string)
PARTS (PID : integer, PNAME : string, COLOR : string)
CATALOG (SID : integer, PID : integer, COST : real)
The key fields are underlined, and the domain of each field is listed after the field name. Thus, SID is the key
for SUPPLIERS, PID is the key for PARTS, and SID and PID together form the key for CATALOG. The
CATALOG relation lists the prices charged for parts by suppliers. CATALOG.SID is a foreign key referring to
SUPPLIERS.SID and CATALOG.PID is a foreign key referring to PARTS.PID.
Write the following queries in SQL.
1. Find the SIDs of suppliers who supply a red part and a green part.
SELECT C.SID
FROM CATALOG C, PART P
WHERE C.PID = P.PID AND P.COLOR = ‘red' AND
C.SID IN (SELECT C.SID
FROM CATALOG C, PART P
WHERE C.PID = P.PID AND P.COLOR = ‘green’)
(SELECT C.SID
FROM CATALOG C, PART P
WHERE C.PID = P.PID AND P.COLOR = ‘red')
INTERSECT
(SELECT C.SID
FROM CATALOG C, PART P
WHERE C.PID = P.PID AND P.COLOR = ‘green’)
(SELECT SID
FROM CATALOG NATURAL JOIN PART
WHERE COLOR = ‘red')
INTERSECT
(SELECT SID
FROM CATALOG NATURAL JOIN PART
WHERE COLOR = ‘green’)
2. Find the SIDs of suppliers who supply a red part or a green part.
SELECT C.SID
FROM CATALOG C, PART P
WHERE C.PID = P.PID AND (P.COLOR = ‘red’ OR P.COLOR = ‘green’
Why is this page out of focus?
This is a Premium document. Become Premium to read the whole document.
Why is this page out of focus?
This is a Premium document. Become Premium to read the whole document.