LAB 6

create table suppliers(

sid number(9,0) primary key,

sname varchar2(30),

address varchar2(40)

);

create table parts(

pid number(9,0) primary key,

pname varchar2(40),

color varchar2(15)

);

create table catalog(

sid number(9,0),

pid number(9,0),

cost number(10,2),

primary key(sid,pid),

foreign key(sid) references suppliers,

foreign key(pid) references parts

);

Insert values in Suppiler table

1,Acme Widget Suppliers,"1 Grub St., Potemkin Village, IL 61801"

2,Big Red Tool and Die,"4 My Way, Bermuda Shorts, OR 90305"

3,Perfunctory Parts,"99999 Short Pier, Terra Del Fuego, TX 41299"

4,Alien Aircaft Inc.,"2 Groom Lake, Rachel, NV 51902"

Insert values in catalog table

1,3,0.50

1,4,0.50

1,8,11.70

2,3,0.55

2,8,7.95

2,1,16.50

3,8,12.50

3,9,1.00

4,5,2.20

4,6,1247548.23

4,7,1247548.23

Insert values in parts table

1,Left Handed Bacon Stretcher Cover,Red

2,Smoke Shifter End,Black

3,Acme Widget Washer,Red

4,Acme Widget Washer,Silver

5,I Brake for Crop Circles Sticker,Translucent

6,Anti-Gravity Turbine Generator,Cyan

7,Anti-Gravity Turbine Generator,Magenta

8,Fire Hydrant Cap,Red

9,7 Segment Display,Green

Write the SQL queries for the following

1 Find the pnames of parts for which there is some supplier.

2. Find the snames of suppliers who supply every part.

3. Find the snames of suppliers who supply every red part.

4. Find the pnames of parts supplied by Acme Widget Suppliers and no one else.

5. Find the sids of suppliers who charge more for some part than the average cost of

that part (averaged over all the suppliers who supply that part).

6. For each part, find the sname of the supplier who charges the most for that part.

7. Find the sids of suppliers who supply only red parts.

8. Find the sids of suppliers who supply a red part and a green part.