Question

Consider the following schema: SUPPLIERS (SID: integer, SNAME: string, STREET: string, CITY: string, ZIP: string) PARTS...

Consider the following schema:

SUPPLIERS (SID: integer, SNAME: string, STREET: string, CITY: string, ZIP: string) PARTS (PID: integer, PNAME: string, COLOR: string) CATALOG (SID: integer, PID: integer, COST: real)

The primary key attributes are underlined, and the domain of each attribute is listed after the attribute name. Thus, SID is the primary key for SUPPLIERS, PID is the primary key for PARTS, and SID and PID together form the primary key for CATALOG. Attribute SID in CATALOG is a foreign key that refers to the primary key SID of SUPPLIERS and PID in CATALOG is a foreign key that refers to the primary key PID of PARTS. The CATALOG relation lists the prices charged for parts by suppliers.

State what the following query computes.

0. πCITY (πPID (σ COLOR = 'green' (PARTS) ) * σ COST>50 (CATALOG) * πSID, CITY (SUPPLIERS) )

Write the following queries in relational algebra.

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

2. Find the names of parts supplied by suppliers who are at 1 Central Ave.

3. Find the names of suppliers who supply some red part.

4. Find the SIDs of suppliers who supply some red or green part.

5. Find the SID of suppliers who supply some red part or whose address is '221 Packer Street'.

6. Find the SIDs of suppliers who supply some red part and some green part.

7. Find the PIDs of parts that are red or are supplied by a supplier who is at the city of Newark.

8. Find the PIDs of parts supplied by a supplier who is at the city of Newark and by a supplier who is at the city of Trenton.

9. Find the PIDs of parts supplied by every supplier.

10. Find the PIDs of parts supplied by every supplier who supplies at least one part.

11. Find the SIDs of suppliers who supply at least two different parts (you are not allowed to use a grouping/aggregation operation for this query).

12. Find the SIDs of suppliers who supply at least two different parts (you have to use a grouping/aggregation operation for this query).

13. For every part, find its PID, its PNAME and the number of suppliers who sell it.

14. List the PID, PNAME and average cost of all parts.

15. Find the average cost of red parts.

16. Find the average cost of parts supplied by suppliers named 'Yosemite Sham'.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Find the names of parts for which there is some supplier
Result<- Π PNAME ((π PID CATALOG) * (π PID,PNAME PARTS))


2. Find the names of parts supplied by suppliers who are at 1 Central Ave.
Result<- Π PNAME ((π SID (σ STREET=’1 Central Ave’ SUPPLIERS )) * (π SID,PID CATALOG) * (π
PID,PNAME PARTS))


3. Find the names of suppliers who supply some red part.
Result<-Π SNAME ((π PID (σ COLOR = 'red' )PARTS )* (π SID,PID CATALOG)*( π SID,SNAME SUPPLIERS))


4. Find the SIDs of suppliers who supply some red or green part.
Result<-Π SID ((π PID(σ COLOR = 'red' U COLOR = 'green' )PARTS)* (π SID,PID CATALOG)* (π SID SUPPLIERS))


5. Find the SID of suppliers who supply some red part or whose address is '221 Packer Street'.
Result<-Π SID ((π PID (σ COLOR = 'red' U STREET = '221 Packer Street') PARTS)* (π SID,PID CATALOG)* (π SID
SUPPLIERS) )


6. Find the SIDs of suppliers who supply some red part and some green part.
Result<-Π SID((π PID (σ COLOR = 'red' ^ COLOR = 'green') PARTS)* (π SID,PID CATALOG))


7. Find the PIDs of parts that are red or are supplied by a supplier who is at the city of Newark.

Result<-Π PID ((π PID (σ COLOR = 'red' U CITY = 'Newark') PARTS)* (π SID,PID CATALOG)* (π SID SUPPLIERS))


8. Find the PIDs of parts supplied by a supplier who is at the city of Newark and by a supplier who is at the city of
Trenton.
Result<-Π PID ((π PID (σ COLOR = 'Trenton' ^ CITY = 'Newark') PARTS)* (π SID,PID CATALOG)* (π SID SUPPLIERS))


9. Find the PIDs of parts supplied by every supplier.
Result<-Π PID , SID CATALOG ÷ Π SID SUPPLIERS


10. Find the PIDs of parts supplied by every supplier who supplies at least one part.
Result<-Π PID , SID CATALOG ÷ Π SID CATALOG


11. Find the PIDs of parts supplied by every supplier who is at the city of Newark or at the city of Trenton
(equivalently: find the PIDs of parts supplied by every supplier who is at the city of Newark and by every supplier
who is at the city of Trenton).
T1 <-Π SID (σ CITY = 'Trenton' U CITY = 'Newark' (SUPPLIERS)
T2<-Π PID,SID CATALOG
Result<- T2÷ T1
T1 <-Π SID (σ CITY = 'Trenton' ^ CITY = 'Newark' (SUPPLIERS)
T2<-Π PID,SID CATALOG
Result<- T2÷ T1


12. Find the PIDs of parts supplied by every supplier who is at the city of Newark or by every supplier who is at the
city of Trenton.
T1 <-Π SID (σ CITY = 'Trenton' (SUPPLIERS)
T2<-Π PID,SID CATALOG
T3<- T2÷ T1
T 4<-Π SID (σ CITY = 'Newark' (SUPPLIERS)
T5<-Π PID,SID CATALOG
T6<- T2÷ T1
T7<- T6 U T3


13. Which one of the queries 11 and 12 is more restrictive (if any)?
12 is more restrictive.


14. Find pairs of PIDs such that the part with the first PID is sold at a higher price by a supplier than the part with the
second PID.
RESULT<-Π PID,PID1 [CATALOG ∞ ∫(CATALOG)]
PID=PID1 PID->PID1
COST>COST1 COST->COST1

15. Find the SIDs of suppliers who supply at least two different parts (you are not allowed to use a
grouping/aggregation operation for this query).
T1<- ∫PID-> PID1 CATALOG
T2<- Π SID ( σ PID≠ PID1 (T1 * CATALOG))


16. Find the SIDs of suppliers who supply at least two different parts (you have to use a grouping/aggregation operation
for this query) .
T1<- SID FCOUNT(PID) CATALOG
T2<- ∫ FCOUNT -> NOS_OF_COUNT T1
RESULT <- Π SID (σ NOS_OF_COUNTS>2) T2


17. For every part supplied by a supplier who is at the city of Newark, print the PID and the SID and the name of the
suppliers who sell it at the highest price.
T1<- σ CITY = ‘NEWARK’ (SUPPLIERS)
T2<- Π SID (F(Max(cost)) CATALOG)
RESULT<- Π PID,SID,SNAME (T1*T2)


18. For every part, find its PID, its PNAME and the number of suppliers who sell it.
T1<- Π PID,PNAME,SID (CATALOG*PARTS) )
RESULT<- Π PID,PNAME,FCOUNT(SID) T1


19. List the PID, PNAME and average cost of all parts.
T1<- FAVG(COST) CATALOG
RESULT<-Π PID ,PNAME ,FAVG(COST) (PARTS *T1)


20. Find the average cost of red parts.
T1 <- σ COLOR = 'RED' (PARTS)
T2 <- F avg(COST) (ΠCOST (CATALOG*T1) )


21. Find the average cost of parts supplied by suppliers named 'Yosemite Sham'.
T1 <- σ SNAME = 'Yosemite Sham' (SUPPLIERS)
T2 <- F avg(COST) (ΠCOST (CATALOG*T1))

Add a comment
Know the answer?
Add Answer to:
Consider the following schema: SUPPLIERS (SID: integer, SNAME: string, STREET: string, CITY: string, ZIP: string) PARTS...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • EXERCISE 1 (SQL Queries) Consider the following schema: SUPPLIERS (SID : integer, SNAME : string, CITY...

    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...

  • Please finish all parts, thanks! 2) Consider the following schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid:integer, pname: string, color: string ) Catalog( sid: integer, pid...

    Please finish all parts, thanks! 2) 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) Write the following queries in relational algebra. a) Find the names of suppliers who supply some red part b) Find the sids of suppliers who supply some red or green part c) Find the sids of suppliers who supply some red and some green part. d) Find the sids of suppliers...

  • Answer the following five (5) questions, based on the schema provided.

    C. Answer the following five (5) questions, based on the schema provided.Consider the following schema:Supplier (sid: integer, sname: string, address: string)Part(pid: integer, pname: string, , color: string)Catalog(sid: integer, pid: integer, cost: real)The relation Supplier stores suppliers and the primary key of that relation is sid. The relation Part stores parts, and pid is the primary key of that relation. Finally, Catalog stores which supplier supplies which part and at which cost (price). The primary key is the combination of the...

  • SQL Queries (1)

    Suppliers(sid: integer, sname: string, address:string)Parts(pid: integer, pname: string, color: string)Catalog(sid: integer, pid: integer, cost: real)The Catalog relation lists the prices charged for parts bySuppliers. Write the following queries in SQL:1) Find the pnames of parts supplied by Acme Widget Suppliers andno one else.2) Find the sids of suppliers who charge more for some partthan the average cost of that part (averaged over all the supplierswho supply that part).3) For each part, find the sname of the supplier who chargesthe most...

  • In .sql Given the following relational schemas, answer the following questions: Suppliers(sid: int, sname: VARCHAR(30), address:...

    In .sql Given the following relational schemas, answer the following questions: Suppliers(sid: int, sname: VARCHAR(30), address: VARCHAR(50)) Parts(pid: int, pname: VARCHAR(30), color: VARCHAR(10)) Catalog(sid: int, pid: int, cost: double) c. (8 points) List sid, sname, and address of all suppliers who supply at least one part. In other words, the answer must not show sid and sname of any supplier who does not have its sid in the Catalog table d. (4 points) Find all distinct black parts in the...

  • Any help appreciated! Question 1 (5 points). Answer each of the following questions briefly. The questions...

    Any help appreciated! Question 1 (5 points). Answer each of the following questions briefly. The questions are based on the following relational schema: Emp( eid: integer, ename: string, age: integer, sala1l1: real) Works( eid: integer, did: integer, pet_time: integer) Dept(did: integer, dname: string, budget: real, managerid: integer) 1. Give an example of a foreign key constraint that involves the Dept relation. 2. Write the SQL statements required to create the preceding relations, including appropriate versions of all primary and foreign...

  • consider the following relational database that records details of parts and suppliers. Primary keys are underlined...

    consider the following relational database that records details of parts and suppliers. Primary keys are underlined and the Foreign Keys are identified with (FK). Suppliers (sid, sname, address, credit) Parts (pid, pname, color) Catalog (sid (FK), pid (FK), cost) The credit attribute denotes the size of the supplier’s credit account. The Catalog relation lists the prices charged for parts by Suppliers. Which of the following queries returns the snames of suppliers who supply every part? Select one or more: a....

  • Consider a database schema with three relations: - Parts (pid:integer, pname:string, year:integer, price:integer) -Suppliers (sid:integer, sname:...

    Consider a database schema with three relations: - Parts (pid:integer, pname:string, year:integer, price:integer) -Suppliers (sid:integer, sname: string, state:string, zipcode:string) -Orders (pid:integer, sid:integer, quantity:integer) The description is as follows: a factory keeps a database with parts that it uses, the suppliers of those parts, and purchase orders. Each part is uniquely identified by pid. Each part has a string description pname, year of fabrication and price per unit. Parts are provided by suppliers, and each supplier is uniquely identified by sid....

  • Consider the following database Relation Schemas: Relation Schemas: Suppliers(SID CHAR(5), Parts(pID VARCHAR(5), type VARCHAR(15), pName VARCHAR(35),...

    Consider the following database Relation Schemas: Relation Schemas: Suppliers(SID CHAR(5), Parts(pID VARCHAR(5), type VARCHAR(15), pName VARCHAR(35), sName VARCHAR(15), address VARCHAR(30, city VARCHAR(20), state CHAR(2), PRIMARY KEY(sID); PRIMARY KEY(pID) Catalog(sID CHAR(5), pID VARCHAR(5), ty SMALLINT, cost FLOAT (10,2), PRIMARY KEY(sid, pid), FOREIGN KEY(sid) REFERENCES Suppliers(SID), FOREIGN KEY (pid) REFERENCES Parts pID) The meaning of these relations is straightforward; for example, the Catalog relation lists the prices charged for parts by Suppliers. Instances of the relations Suppliers sName address SID cit state...

  • Please HELP, THANK YOU SO MUCH Consider the below schema of the university database (keys are...

    Please HELP, THANK YOU SO MUCH Consider the below schema of the university database (keys are in bold and underline) Part(pid: string, pname: string, description: string, color: string) Department(did: string, dnamestring, address: string) Supplier(sid string,.sname:string, address:string) Order(did:string. sid string pidstring, time:string, quantityreal, pricereal) The key fields are underlined, and the domain of each field is listed after the field name. Thus pid is the key for Part, did is the key for Department, sid is the key for Supplier, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT