ER Exercises

Exercise ER-1

What is the cardinality and existence of each of the following relationships in just the direction given? State any assumptions you have to make.

  1. Husband to wife
  2. Student to degree
  3. Child to parent
  4. Player to team
  5. Student to course

Answer to Exercise ER-1

Exercise ER-2

For each of the following pairs of rules, identify two entity types and one relationship. State the cardinality and existence of the relationship in each case. If you don't think enough information is available to define either of these, then state an assumption that makes it clear. Draw the ER diagram.

  1. A department employs many persons. A person is employed by, at most, one department.
  2. A manager manages, at most, one department. A department is managed by, at most, one manager.
  3. An author may write many books. A book may be written by many authors.
  4. A team consists of many players. A player plays for only one team.
  5. A lecturer teaches, at most, one course. A course is taught by exactly one lecturer.
  6. A flight-leg connects two airports. An airport is used by many flight-legs.
  7. A purchase order may be for many products. A product may appear on many purchase orders.
  8. A customer may submit many orders. An order is for exactly one customer.

Answer to Exercise ER-2

Exercise ER-3

Draw an ER diagram for the following. Be sure to indicate the existence and cardinality for each relationship.

  1. A college runs many classes. Each class may be taught by several teachers, and a teacher may teach several classes. A particular class always uses the same room. Because classes may meet at different times or on different evenings, it is possible for different classes to use the same room.
  2. Each employee in an engineering company has at most one recognized skill, but a given skill may be possessed by several employees. An employee is able to operate a given machine-type (e.g., lathe, grinder) if he has one of several skills, but each skill is associated with the operation of only one machine type. Possession of a given skill (e.g., mechanic, electrician) allows an employee to maintain several machine-types, although maintenance of any given machine-type requires a specific skill (e.g., a lathe must be maintained by a mechanic).

Answer to Exercise ER-3

Exercise ER-4

Draw an ER diagram for each of the following situations. On the diagram be sure to identify the cardinality, existence, and optionality (for subtypes) of each relationship.

  1. A company has a number of employees. Each employee may be assigned to one or more projects, or may not be assigned to a project. A project must have at least one employee assigned, and may have several employees assigned.
  2. A university has a large number of courses in its catalog. Each course may have one or more other courses as prerequisistes, or may have no prerequisites.
  3. A college course may have one or more scheduled sections, or may not have a scheduled section.
  4. A hospital patient has a patient history. Each patient has one or more history records (we assume that the initial patient visit is always recorded as an instance of the history). Each patient history record belongs to exactly one patient.
  5. A video store may stock more than one copy of a given movie. It is also true that the store may not have a single copy of a paticular movie.

Answer to Exercise ER-4

Exercise ER-5

Draw an ER diagram to represent the following entity types and the natural relationships among them: Vehicle, Land-vehicle, Air-vehicle, Water-vehicle, Ocean-vessel, River-raft, Helicopter, Rail-vehicle, Road-vehicle, Car, Airplane, Bicycle.

Answer to Exercise ER-5

Exercise ER-6

Draw an ER diagram that best represents the following situation. There are three types of accounts in a bank, with these attributes:

  1. Checking: Acct-no, Date-opened, Balance, Service-charge
  2. Savings: Acct-no, Date-opened, Balance, Interest-rate
  3. Loan: Acct-no, Date-opened, Balance, Acct-limit

Answer to Exercise ER-6

Exercise ER-7

Consider the following diagram:

  1. What are the minimum and maximum number of Cs that can be associated with any one A? This is the same as asking “What are the existence and cardinality for the C to A relationship?”
  2. Substitute A:person and B:manage and C:project in the above ER diagram. Suppose that someone told you that the following three facts are true. Are these consistent with the diagram? Answer yes or no for each of the three facts. If your answer is no, then explain why it is inconsistent.
    1. Mackenzie manages the White project.
    2. Lindsey manages the Brown and Black projects.
    3. Joe doesn't manage any projects.

Answer to Exercise ER-7

Exercise ER-8

The following facts make up all of the leads relation between person and project:

  • Jennifer leads the Southpark project.
  • Jennifer leads the Briarwood project.
  • Don leads the Eastgate project.

You do not know whether or not there are any other people or any other projects. Which diagram(s) that is (are) consistent with this set of three facts. For example, you might answer “1, 4” if both 1 and 4 are consistent with the above facts.


Answer to Exercise ER-8

Exercise ER-9

For each of the following sets of sentences, draw the corresponding ER diagram.

  1. An account can be charged against many projects, though it may not be charged against any. A project must have at least one, though it may have many, accounts charged against it.
  2. Projects must be classified as either top secret or civilian (but not both). There is information specific to top secret projects and specific to civilian projects that we want to record.
  3. An employee must manage exactly one department. A department may or may not have one employee manage it.
  4. Men are only allowed to supervise men. Women are only allowed to supervise women. We do not want to allow the database to hold data representing a man supervising a woman. An employee, regardless of sex, is assigned to exactly one office, with each office having exactly one employee in it. (Be sure to include the office entity in this diagram.)

Answer to Exercise ER-9

Exercise ER-10

The following descriptions all have to do with a holding company for food service companies. You should answer each one separately from the others.

  1. Each chain consists of 50 to 300 stores that are owned by ACTME, the holding company for several restaurant chains and two caterers.
  2. Menu items are wide ranging, and can be classified by the section of the menu (appetizer, dessert, etc.) in which each is presented and by ethnic group (Italian, Hungarian, etc.) to which it belongs.
  3. The menu of each restaurant changes every couple months; management likes to keep track of past menus to track which ones have been successful.
  4. Each menu item is made of several ingredients (eggs, bacon, etc.) that are used in a certain quantity.
  5. Ingredients can be acquired from several suppliers. Ingredients are acquired by sending orders for several goods using the vendor's item numbers. The item number for each of these ingredients varies across suppliers, so if you are going to order eggs from supplier # 1, then you might order item 52 while from supplier # 2 you might order item J216. The company keeps price and item numbers for all the ingredients for all its menu items — and even for some ingredients which it is not currently using in any menu items. The quantity needed for each ingredient is also kept. The current price of these goods is maintained though the historical price is not. Because of special deals and volume discounts, the price at which a good is acquired is often different from its list price. Thus, the database must retain the price at which a good is actually acquired.

Answer to Exercise ER-10

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License