0% found this document useful (0 votes)
203 views11 pages

hw1 Sol

This document contains sample problems and solutions for an ER modeling assignment. It includes examples of modeling professors teaching courses, employees and their relationships in a company, and information about an airport database. ER diagrams are provided as answers. The document also contains problems for relational algebra, tuple calculus, and domain calculus queries over sample schemas.

Uploaded by

solanki_558
Copyright
© Attribution Non-Commercial (BY-NC)
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)
203 views11 pages

hw1 Sol

This document contains sample problems and solutions for an ER modeling assignment. It includes examples of modeling professors teaching courses, employees and their relationships in a company, and information about an airport database. ER diagrams are provided as answers. The document also contains problems for relational algebra, tuple calculus, and domain calculus queries over sample schemas.

Uploaded by

solanki_558
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 11

Homework 1

July 20, 2008

Problem 2.2

A university database contains information about professors (identied by social security number, or SSN) and courses (identied by courseid). Professors teach courses; each of the following situations concerns the Teaches relationship set. For each situation, draw an ER diagram that describes it (assuming no further constraints hold). 1. Professors can teach the same course in several semesters, and each oering must be recorded. Answer: Figure 1 2. Professors can teach the same course in several semesters, and only the most recent such oering needs to be recorded. (Assume this condition applies in all subsequent questions.) Answer: Figure 2 3. Every professor must teach some course. Answer: Figure 3 4. Every professor teaches exactly one course (no more, no less). Answer: Figure 4 5. Every professor teaches exactly one course (no more, no less), and every course must be taught by some professor. Answer: Figure 5 Now suppose that certain courses can be taught by a team of professors jointly, but it is possible that no one professor in a team can teach the course. Model this situation, introducing additional entity sets and relationship sets if necessary. Answer: Figure 6

Figure 1: E-R diagram for 2.2.1

Problem 2.4

A company database needs to store information about employees (identied by ssn, with salary and phone as attributes), departments (identied by dno, with dname and budget as attributes), and children of employees (with name and age as attributes). Employees work in departments; each department is managed by an employee; a child must be identied uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. We are not interested in information about a child once the parent leaves the company. Draw an ER diagram that captures this information. Answer: Figure 7

Problem 2.6

Computer Sciences Department frequent iers have been complaining to Dane County Airport ocials about the poor organization at the airport. As a result, the ocials decided that all information related to the airport should be organized using a DBMS, and you have been hired to design the database. Your rst task is to organize the information about all the airplanes stationed and maintained at the airport. The relevant information is as follows: Every airplane has a registration number, and each airplane is of a specic model. The airport accommodates a number of airplane models, and each model is identied by a model number (e.g., DC-10) and has a capacity and a weight.

Figure 2: E-R diagram for 2.2.2 A number of technicians work at the airport. You need to store the name, SSN, address, phone number, and salary of each technician. Each technician is an expert on one or more plane model(s), and his or her expertise may overlap with that of other technicians. This information about technicians must also be recorded. Trac controllers must have an annual medical examination. For each trac controller, you must store the date of the most recent exam. All airport employees (including technicians) belong to a union. You must store the union membership number of each employee. You can assume that each employee is uniquely identied by a social security number. The airport has a number of tests that are used periodically to ensure that airplanes are still airworthy. Each test has a Federal Aviation Administration (FAA) test number, a name, and a maximum possible score. The FAA requires the airport to keep track of each time a given airplane is tested by a given technician using a given test. For each testing event, the information needed is the date, the number of hours the technician spent doing the test, and the score the airplane received on the test. Draw an ER diagram for the airport database. Be sure to indicate the various attributes of each entity and relationship set; also specify the key and participation constraints for each relationship set. Specify any necessary overlap and covering constraints as well (in English). The FAA passes a regulation that tests on a plane must be conducted by a technician who is an expert on that model. How would you express this constraint in the ER diagram? If you cannot express it, explain briey.

Figure 3: E-R diagram for 2.2.3 Answer: Figure 8

Problem 4.3

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) The key elds are underlined, and the domain of each eld is listed after the eld name. Therefore sid is the key for Suppliers, pid is the key for Parts, and sid and pid together form the key for Catalog. The Catalog relation lists the prices charged for parts by Suppliers. Write the following queries in relational algebra, tuple relational calculus, and domain relational calculus: 1. Find the names of suppliers who supply some red part. Answer: Figure 9 4. Find the sids of suppliers who supply some red part and some green part. Answer: Figure 10 7. Find the sids of suppliers who supply every red or green part. Answer: Figure 11 10. Find the pids of parts supplied by at least two dierent suppliers. Answer: Figure 12

Figure 4: E-R diagram for 2.2.4

Figure 5: E-R diagram for 2.2.5

Problem 4.4

1. sname (sid ((color= red P arts) (cost<100 Catalog )) Suppliers) Answer: Figure Find the Supplier names of the suppliers who supply a red part that costs less than 100 dollars. 3. (sname ((color= red P arts) (cost<100 Catalog ) Suppliers))(sname ((color= green P arts) (cost<100 Catalog ) Suppliers)) Answer: Figure Find the Supplier names of the suppliers who supply a red part that costs less than 100 dollars and a green part that costs less than 100 dollars. 5. sname ((sid,sname ((color= red P arts) (cost<100 Catalog ) Suppliers)) (sname ((sid,sname ((color= green P arts) (cost<100 Catalog ) Suppliers))) Answer: Figure Find the Supplier names of the suppliers who supply a red part that costs less than 100 dollars and a green part that costs less than 100 dollars.

Figure 6: E-R diagram for 2.2.6

Problem 4.5

Consider the following relations containing airline ight information: Flights(no: integer, from: string, to: string, distance: integer, departs: time, arrives: time) Aircraft(aid: integer, aname: string, cruisingrange: integer) Certied(eid: integer, aid: integer) Employees(eid: integer, ename: string, salary: integer) Note that the Employees relation describes pilots and other kinds of employees as well; every pilot is certied for some aircraft (otherwise, he or she would not qualify as a pilot), and only pilots are certied to y. Write the following queries in relational algebra, tuple relational calculus, and domain relational calculus. Note that some of these queries may not be expressible in relational algebra (and, therefore, also not expressible in tuple and domain relational calculus)! For such queries, informally explain why they cannot be expressed. (See the exercises at the end of Chapter 5 for additional queries over the airline schema.) 2. Find the names of pilots certied for some Boeing aircraft. Answer: Figure 13 5. Find the names of pilots who can operate planes with a range greater than 3,000 miles but are not certied on any Boeing aircraft. Answer: Figure 14 8. Find the eids of employees who are certied for the largest number of aircraft. Answer: Figure This cannot be expressed in relational algebra (or calculus) because there is no operator to count, and this query requires the ability to count up to a number that depends on the data. The query can however be expressed in SQL as follows: SELECT Temp.eid FROM ( SELECT C.eid AS eid, COUNT (C.aid) AS cnt, FROM Certied C GROUP BY C.eid) AS Temp WHERE Temp.cnt = ( SELECT MAX (Temp.cnt) FROM Temp)

Figure 7: E-R diagram for 2.4 10. Find the total amount paid to employees as salaries. Answer: Figure This cannot be expressed in relational algebra (or calculus) because there is no operator to sum values. The query can however be expressed in SQL as follows: SELECT SUM (E.salaries) FROM Employees E

Figure 8: E-R diagram for 2.6

Figure 9: Figure for 4.3.1

Figure 10: Figure for 4.3.4

Figure 11: Figure for 4.3.7

Figure 12: Figure for 4.3.10

Figure 13: Figure for 4.5.2

Figure 14: Figure for 4.5.5

You might also like