Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Explain the difference among the terms Primary Key, Candidate Key and Super Key

ID: 3823028 • Letter: E

Question

Explain the difference among the terms Primary Key, Candidate Key and Super Key with suitable examples.
Q2
Consider the following schema:
Supplier(sid: integer, sname: string, address: string)
Part(pid: integer, pname: string, colour: string)
Catalog(sid: integer, pid: integer, cost: real)
The relation Supplier stores suppliers and the key of that relation is sid. The relation
Part stores parts, and pid is the key of that relation. Finally, Catalog stores which
supplier supplies which part at which cost. The key is the combination of the two
attributes sid and pid.
A. Write the queries in relational algebra for the following:
1. Find the names of suppliers who supply some red part.
2. Find the IDs of suppliers who supply some red or green part.
3. Find the IDs of suppliers who supply some red part or are based at 21 George
Street.
4. Find the IDs of suppliers who supply some red part and some green part.

B. For each of the following relational algebra queries, write in English what they mean.
1. sname(colour=’red’(Part) cost<100 (Catalog) Supplier)
2. sname(sid(colour=’red’(Part) cost<100 (Catalog)) Supplier)

Explanation / Answer

A)

1)
SELECT SUP.sname
FROM Suppliers SUP, Parts PAR, Catalog CAT
WHERE PAR.color='red' AND CAT.pid=PAR.pid AND CAT.sid=SUP.sid

2)
SELECT SUP.sid
FROM Suppliers SUP
WHERE (SELECT CAT.pid FROM Catalog CAT WHERE CAT.sid = SUP.sid)
CONTAINS (SELECT pid FROM Parts WHERE color = 'red' OR color = 'green')

3)
(SELECT SUP.sid
FROM Suppliers SUP
WHERE SUP.address = '21 George Street')
UNION
(SELECT CAT.sid
FROM Parts PAR, Catalog CAT
WHERE PAR.color = 'red' AND PAR.pid = CAT.pid)


4)
SELECT CAT1.sid
FROM Catalog CAT1, Parts PAR1, Catalog CAT2, Parts PAR2
WHERE CAT1.pid=PAR1.pid AND PAR1.color='red' AND
CAT2.pid=PAR2.pid AND PAR2.color='green' AND
CAT1.sid=CAT2.sid

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

B)

1) sname(colour=’red’(Part) cost<100 (Catalog) Supplier)

Select supplier names who supply red part and part cost less than 100

2) sname(sid(colour=’red’(Part) cost<100 (Catalog)) Supplier)

Select supplier names and sids who supply red part and part cost less than 100

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote