Mid PDM Answer
Mid PDM Answer
Mid PDM Answer
I. RA
A. First Schema
Suppliers(sID, sName, address)
Parts(pID, pName, colour)
Catalog(sID, pID, price)
Catalog[sID] ⊆ Suppliers[sID]
Catalog[pID] ⊆ Parts[pID]
Note:
● In this schema, everywhere we want values to match across
relations, the attributes have matching names. And everywhere the
attributes have matching names, we want values to match across
relations.
● This means that natural join will do exactly what we want in all
cases.
1. If sID is a key for the Suppliers relation, could it be a
key for the Catalog relation?
Just because it is a key in one relation doesn’t mean it is in another; being
a key is relative to the relation. But is it a key for Catalog? No. We almost
surely want to be able to list multiple parts by one supplier in our catalog.
2. Find the names of all red parts.
3. Find all prices for parts that are red or green. (A part
may have different prices from different manufacturers.)
4. Find the sIDs of all suppliers who supply a part that
is red or green.
B. Second Schema
Employees(number, name, age, salary)
Supervises(boss, employee)
Supervises[boss] ⊆ Employees[number]
Supervises[employee] ⊆ Employees[number]
Note:
● In this schema, wherever we want values to match across relations,
the attributes do not have matching names. This means that natural
join will not force things to match up as we’d like.
● In fact, since there are no attribute names in common across the two
relations, natural join is no different from Cartesian product.
● We are forced to use selection to enforce the necessary matching.
1. What does it say about our domain that employee is a
key for Supervises?
Every employee has one boss.
2. Does the schema allow for an employee with no boss?
Yes.
3. How would the world have to be different if boss were a
key for Supervises?
It would mean that every boss could have at most one employee. Not very
sensible!
4. How would the world have to be different if both boss
and employee together were a key for Supervises?
This would imply that neither alone is a key, since keys are minimal. Thus,
bosses could have multliple employees (sensible) and employees could
have multiple bosses (possibly sensible).
5. Find the names and salaries of all bosses who have an
employee earning more than 100.
C. Third Schema
This schema is for a salon. Services could be things like “haircut” or
“manicure”.
Clients(CID, name, phone)
Staff(SID, name)
Appointments(CID, date, time, service, SID)
Appointments[CID] ⊆ Clients[CID]
Appointments[SID] ⊆ Staff[SID]
Note:
● In this schema, everywhere we want values to match across
relations, the attributes have matching names. But there are also
attributes with matching names whose values we do not want to
match across relations.
● In those cases, that natural join will get rid of many tuples that we
need, so we must use Cartesian product and make any necessary
matching happen using select. (Unless we can remove the problem
attributes first.).
1. Find the appointment time and client name of all
appointments for staff member Giuliano on Feb14. (Assume
that you can compare a date value to “Feb 14” using “=”). At
each step, use projection to pare down to only the attributes
you need.
II. Tree
III. SQL Server
1. Consider the following relations:
g) For each level, print the level and the average age of
students for that level.
h) For all levels except JR, print the level and the average
age of students for that level.
l) For each age value that appears in Students, find the level
value that appears most often. For example, if there are more FR
level students aged 18 than SR, JR, or SO students aged 18, you
should print the pair (18, FR).
Note that the Employees relation describes pilots and other kinds of
employees as well; every pilot is certified for some aircraft, and only pilots
are certified to fly. Write each of the following queries in SQL. (Additional
queries using the same schema are listed in the exercises for Chapter 4.)
a) Find the names of aircraft such that all pilots certified to
operate them have salaries more than $80,000.
b) For each pilot who is certified for more than three aircraft,
find the eid and the maximum cruisingrange of the aircraft for
which she or he is certified.
c) Find the names of pilots whose salary is less than the price
of the cheapest route from Los Angeles to Honolulu.
IV. ERD
V. Reference
1. https://www.eecs.yorku.ca/~papaggel/courses/eecs3421/
docs/tutorials/tut1-ra.pdf
2. https://pages.cs.wisc.edu/~dbbook/openAccess/thirdEdit
ion/qbe.pdf
3. https://www.eecs.yorku.ca/~papaggel/courses/eecs3421/
docs/tutorials/tut2-ra.pdf
4. https://pages.cs.wisc.edu/~dbbook/openAccess/thirdEdit
ion/supporting_material.htm#Students%20and%20Instructors