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

ADC hw3

The document contains solutions to homework questions on relational algebra, tuple relational calculus, and domain relational calculus related to suppliers and parts. It includes queries to find suppliers based on the color of parts they supply, as well as explanations of the queries' outcomes. The document also discusses the implications of query order and projections in relational algebra.

Uploaded by

priyankavoleti99
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)
3 views3 pages

ADC hw3

The document contains solutions to homework questions on relational algebra, tuple relational calculus, and domain relational calculus related to suppliers and parts. It includes queries to find suppliers based on the color of parts they supply, as well as explanations of the queries' outcomes. The document also discusses the implications of query order and projections in relational algebra.

Uploaded by

priyankavoleti99
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

Advanced Database Concepts Homework3

Priyanka Voleti

Q1. Relational Algebra, Tuple Relational Calculus, and Domain


Relational Calculus Solutions
1. Find the names of suppliers who supply some red part.
Relational Algebra:
πsname (πsid ((πpid σcolor=′ red′ (P arts)) ▷◁ Catalog) ▷◁ Suppliers)
Tuple Relational Calculus (TRC):
{S.sname | Suppliers(S) ∧ ∃C∃P (Catalog(C) ∧ P arts(P ) ∧ C.sid = S.sid ∧ C.pid = P.pid ∧ P.color =′ red′ )}
Domain Relational Calculus (DRC):
{S.sname | ∃sid, sname, address, pid, pname (Suppliers(sid, sname, address)
∧ Catalog(sid, pid, cost)
∧ P arts(pid, pname,′ red′ ))}

2. Find the sids of suppliers who supply some red or green part.
Relational Algebra:
πsid (Catalog ▷◁ σcolor=′ red′ ∨color=′ green′ (P arts))
Tuple Relational Calculus (TRC):
{S.sid | Suppliers(S)∧∃C∃P (Catalog(C)∧P arts(P )∧C.sid = S.sid∧C.pid = P.pid∧(P.color =′ red′ ∨P.color =′ green′ ))}
Domain Relational Calculus (DRC):
{sid | ∃sid, pid (Catalog(sid, pid, cost) ∧ (∃pname(P arts(pid, pname,′ red′ ) ∨ P arts(pid, pname,′ green′ ))))}

3. Find the sids of suppliers who supply some red part and some green part.
Relational Algebra:
πsid (πsid (Catalog ▷◁ σcolor=′ red′ (P arts))
∩ πsid (Catalog ▷◁ σcolor=′ green′ (P arts)))
Tuple Relational Calculus (TRC):
{S.sid | Suppliers(S) ∧ ∃C1∃P 1∃C2∃P 2 (Catalog(C1) ∧ P arts(P 1)
∧ Catalog(C2) ∧ P arts(P 2) ∧ C1.sid = S.sid ∧ C2.sid = S.sid
∧ C1.pid = P 1.pid ∧ C2.pid = P 2.pid ∧ P 1.color =′ red′ ∧ P 2.color =′ green′ )}
Domain Relational Calculus (DRC):
{sid | ∃pid1, pid2 (Catalog(sid, pid1, cost1) ∧ Catalog(sid, pid2, cost2)
∧ (∃pname1P arts(pid1, pname1,′ red′ )) ∧ (∃pname2P arts(pid2, pname2,′ green′ ))

1
4. Find the sids of suppliers who supply every part.
Relational Algebra:
πsid (Suppliers) ÷ πpid (P arts)
Tuple Relational Calculus (TRC):

{S.sid | Suppliers(S) ∧ ∀P (P arts(P ) → ∃C(Catalog(C) ∧ C.sid = S.sid ∧ C.pid = P.pid))}

Domain Relational Calculus (DRC):

{sid | ∀pid(P arts(pid, pname, color) → ∃cost(Catalog(sid, pid, cost)))}

5. Find the sids of suppliers who supply every red part.


Relational Algebra:
πsid (Suppliers) ÷ πpid (σcolor=′ red′ (P arts))
Tuple Relational Calculus (TRC):

{S.sid | Suppliers(S) ∧ ∀P (P arts(P ) ∧ P.color =′ red′ → ∃C(Catalog(C) ∧ C.sid = S.sid ∧ C.pid = P.pid))}

Domain Relational Calculus (DRC):

{sid | ∀pid(P arts(pid, pname,′ red′ ) → ∃cost(Catalog(sid, pid, cost)))}

Q2. Explanation of Queries


1.
πsname (πsid (σcolor=′ red′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers)
This query retrieves the names of suppliers who supply red parts with a cost less than 100 units.

2.
πsname (πsid (σcolor=′ red′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers)
This Relational Algebra statement returns no results due to the order of the projection operations. After
projecting sid, it becomes the only remaining field in the result set. Consequently, attempting to project
sname afterward will yield nothing, as sname is no longer available.

3.

(πsname (σcolor=′ red′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers)


∩(πsname (σcolor=′ green′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers)

This query returns the names of suppliers who supply both red and green parts, with the condition that the
cost of both types of parts is less than 100 units.

4.

(πsid (σcolor=′ red′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers)


∩(πsid (σcolor=′ green′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers)

This query finds the sid ’s of suppliers who supply both red and green parts with a cost of less than 100
units.

2
5.

πsname ((πsid,sname (σcolor=′ red′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers)


∩ (πsid,sname (σcolor=′ green′ (P arts)) ▷◁ (σcost<100 (Catalog)) ▷◁ Suppliers))

This query retrieves the names of suppliers who supply both red and green parts with a cost of less than 100
units.

You might also like