Docsity

Homework 3 with Solution - Database Systems | 22C 144, Assignments of Deductive Database Systems

Toggle sidebar
bg1
21:124 / 22C:144, Spring 2002
Homework Assignment #3 Solutions
For the following database schema,
• Supplier (supplierID, supplierName, status, city)
• Part (partID, partName, color, weight, cityWhereStored)
• Project (projectID, projectName, city)
• SPJ (supplierID, partID, projectID, quantity) as specified, answer the following
questions in
• relational algebra (RA)
• tuple relational calculus (TRC)
• domain relational calculus (DRC)
Solution 1
Get supplier IDs for suppliers who supply project NoBrainer. (RA, TRC)
RA: P Supplier.supplierId ( s Project.projectName = ‘NoBrainer’ (Project Join SPJ ))
TRC: { t | $ p e Project (p[projectName] = ‘NoBrainer’
Ÿ $ s e SPJ (s[projectId] = p[projectId] Ÿ t[supplierId] = s[supplierId] )) }
Solution 2
Get all shipments where the quantity is in the range 200 to 500 inclusive. (TRC,
DRC)
TRC: { t | " u e SPJ (u[quantity] >= 200 Ÿ u[quantity] <=500
Ÿ t[supplierID] = u [supplierID] Ÿ t[partID] = u[partID]
Ÿ t[projectID] = u [projectID] Ÿ t[quantity] = u[quantity] )}
DRC: { <s,p,r,q> | $ t ( <s,p,r,q> e SPJ Ÿ q>=200 Ÿ q<=500 )}
pf3
pf4

Partial preview of the text

Download Homework 3 with Solution - Database Systems | 22C 144 and more Assignments Deductive Database Systems in PDF only on Docsity!

21:124 / 22C:144, Spring 2002 Homework Assignment #3 Solutions

For the following database schema,

  • Supplier (supplierID, supplierName, status, city)
  • Part (partID, partName, color, weight, cityWhereStored)
  • Project (projectID, projectName, city)
  • SPJ (supplierID, partID, projectID, quantity) as specified, answer the following questions in
  • relational algebra (RA)
  • tuple relational calculus (TRC)
  • domain relational calculus (DRC) Solution 1 Get supplier IDs for suppliers who supply project NoBrainer. (RA, TRC) RA: P Supplier.supplierId ( s Project.projectName = ‘NoBrainer’ (Project Join SPJ )) TRC: { t | $ p e Project (p[projectName] = ‘NoBrainer’ Ÿ $ s e SPJ (s[projectId] = p[projectId] Ÿ t[supplierId] = s[supplierId] )) } Solution 2 Get all shipments where the quantity is in the range 200 to 500 inclusive. (TRC, DRC) TRC: { t | " u e SPJ (u[quantity] >= 200 Ÿ u[quantity] <= Ÿ t[supplierID] = u [supplierID] Ÿ t[partID] = u[partID] Ÿ t[projectID] = u [projectID] Ÿ t[quantity] = u[quantity] )} DRC: { <s,p,r,q> | $ t ( <s,p,r,q> e SPJ Ÿ q>=200 Ÿ q<=500 )}

Solution 3 Get all supplier ID / part ID / project ID triples such that the indicated supplier, part and project are all colocated (i.e., all in the same city). (DRC, RA) DRC: { <s,p,r> | $ c1 <s, sn, st, c1> e Supplier Ÿ $ c2 <p, pn,, col, wt, c2> e Part Ÿ $ c3 <r, rn, c3> e Project Ÿ c1=c2 Ÿ c2=c3 } RA: P Supplier.supplierID, Part.partID, Project.projectID ( s Supplier.city = Part.cityWhereStored Ÿ Part.cityWhereStored = Project.city (Supplier x Part x Project)) Solution 4 Get full details for parts supplied by Chicago suppliers. (RA, TRC). RA: P Part.partID, Part.partName, Part.color, Part.weight, Part.cityWhereStored ( s Supplier.city = ‘Chicago’ ( SPJ join Supplier join Part))

TRC: { t | $ s e Supplier (s[city] = ‘Chicago’ Ÿ $ u e SPJ (u[supplierID] = s[supplierID] Ÿ $ p e Parts( p[partID] = u[partID] Ÿ t[partID] = p[partID] Ÿ t[partName] = p[partName] Ÿ t[color] = p[color] Ÿ t[weight] = p[weight] Ÿ t[cityWhereStored] = p[cityWhereStored] ))) }

Solution 5 Get supplier IDs for suppliers with a lower status than supplier 42. (TRC, DRC) TRC: { t | $ s e Supplier ( s[supplierID] = ‘42’ Ÿ $ u e Supplier (t[supplierID] = u[supplierID] Ÿ u[status] < s[status] )) }

Solution 8 Get supplier IDs for suppliers who supply all projects. (TRC, DRC) TRC { t | " r e Project fi $ s e SPJ ( s[projectID] = p[projectID] Ÿ t[supplierID] = s[supplierID] ) }

DRC { | " pid ( <pid, pname, pcity> e Project ) fi $ sid (<sid, partid, pid, qty> e SPJ) }