0% found this document useful (0 votes)
56 views3 pages

Pid Color Red' Sid Name

The document describes a schema with Suppliers, Parts, and Catalog tables and poses a series of questions about finding supplier information based on part attributes. It provides the multi-step SQL queries to answer each question, beginning with finding the names of suppliers who supply red parts, then the IDs of suppliers for red or green parts, and continuing through queries for suppliers of red parts or at a specific address, red and green parts, every part, every red part, and every red or green part.

Uploaded by

tarun06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views3 pages

Pid Color Red' Sid Name

The document describes a schema with Suppliers, Parts, and Catalog tables and poses a series of questions about finding supplier information based on part attributes. It provides the multi-step SQL queries to answer each question, beginning with finding the names of suppliers who supply red parts, then the IDs of suppliers for red or green parts, and continuing through queries for suppliers of red parts or at a specific address, red and green parts, every part, every red part, and every red or green part.

Uploaded by

tarun06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Q) Consider the following schema:

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


Parts (pid : integer, pname : string, color : string)
Catalog (sid : integer, pid : integer, cost : real)
The key fields are underlined and domain of each field is listed after the field
name

1) Find the name of suppliers who supply some red parts


We first find the pids of parts that are red in color and then we compute the
natural join of this with catalog from this we project sid which gives ids of the
supplier who supply some red part, then we take the natural join of this with
supplier and project names which gives us the names of suppliers who supply
some red part
Step 1 :

R1 = pid(color = redparts)

Step 2 :

R2 = sid(R1 $ Catalog )

Step 3 :

R3=name(R2 $ Sppliers)

Required answer is R3

2) Find the sids of suppliers who supply some red or green parts

Step1:

R1 = pid(color = red V greenparts)

Step 2 :

R2 = sid(R1 $ Catalog)

Same as above one but here we have to choose red or green parts and we have
to have sids of suppliers so we can stop after step 2 after choosing parts either
in red color or green color

3) Find the sids of suppliers who supply some red part or are at 221 packer Ave
Sids of suppliers who supply some red part
Step 1 : R1 = pid(color = redparts)
Step 2 :

R2 = sid(R1 $ Catalog )

Sids of suppiers who are at 221 packer Ave


Step 1 : R3 = sidaddress = 221 packer Ave(Suppliers)
Therefore sids of suppliers who supply some red part or are at 221 packer Ave
Is R2 U R3

4) Find the sids of suppliers who supply some red part and some green part
A) R1 = sid(pid(color = red parts) $ Catalog)
R2 = sid(pid(color = greenparts) $ Catalog)
From question one we get the sids of suppliers who supply some red part (R1)
Similarly R2 is the sids of suppliers who supply some green part
Required list of sids who supply some red and some green part is R1
Intersection R2

5) Find the sids of suppliers who supply every part


A) R1=sid,pid Catalog
R2=pidParts
R1/R2 give us the required list of sids of suppliers who supply every part

6)Find the sids of suppliers who supply every red part


A)This is same as previous one but in R2 we consider only red parts
R1= sid,pid Catalog
R2=pidcolr=redparts
So required answer is R1/R2

7)Find the sids of suppliers who supply every red or green part
A) R1= sid,pid Catalog
R2=pidcolr=red v green parts
R1/R2 gives the sids of suppliers who supply every part which is either red in
Color or green in color

You might also like