Solution of Exercise 1: ER-Diagrams Due: November 5, Ross closing time Name: Login: Student Number: Print out this exercise and answer the questions on the printout. For Problem 4 you should attach extra pages, as needed. Remember to register for the course so that your exercise may be graded. Problem 2 (35 points) Below we present several entity relationship diagrams for modeling information about authors, editors and books. Note that aid is the key of Authors, eid is the key of Editors and bid is the key of Books. For each of the entity relationship diagrams below: (a) State briefly the meaning of the diagram. Emphasize the constraints in the diagrams. (b) Suppose that there are 300 authors, 1000 books and 10 editors. What is the maximal number of triples that R contains? (c) Suppose that there are 300 authors, 1000 books and 10 editors. What is the minimal number of triples that R contains? Editors R eid Books bid aid Authors (1a) Meaning: The diagram models information about the editing of books written by authors. Each editor edits any number of books and works with any number of authors. Each book is written by any number of authors and is edited by any number of editors. Each author writes any number of books and works with any number of editors. (1b) Maximal number of triples: 3000000 (1c) Minimal number of triples: 0 1 Editors R eid Books bid aid Authors (2a) Meaning: Each editor edits any number of books and works with any number of authors. Each book is written by any number of authors and is edited by any number of editors. Each author writes at most one book and works with at most one editor. (2b) Maximal number of triples: 300 (2c) Minimal number of triples: 0 Editors R eid Books bid aid Authors (3a) Meaning: Each editor edits at most one book and works with at most one author. Each book is written by any number of authors and is edited by any number of editors. Each author writes at most one book and works with at most one editor. (3b) Maximal number of triples: 10 (3c) Minimal number of triples: 0 Editors R eid Books bid aid Authors (4a) Meaning: Each editor edits at least one book and works with at least one author. Each book is written by any number of authors and is edited by any number of editors. Each author writes exactly one book and works with exactly one editor. (4b) Maximal number of triples: 300 (4c) Minimal number of triples: 300 Editors R eid Books bid aid Authors 2 (5a) Meaning: Each editor edits at least one book and works with at least one author. Each book is written by at least one author and is edited by at least one editor. Each author writes at least one book and works with at least one editor. (5b) Maximal number of triples: 3000000 (5c) Minimal number of triples: 1000 Problem 3 (25 Points) 1. As in Problem 2, we consider information about Authors, Books and Editors. We wish to store information about which author wrote which book with which editor. Two basic approaches can be taken to model this information: Editors Edits Books eid bid Writes Contact Editors R eid Books Authors bid aid aid Authors (a) (b) (a) Assuming that there are no further constraints on the information, which of the two diagrams presented are more suitable for modeling the information? Can the information be captured in both diagrams? Explain. Diagram (a) clearly captures the required information since the relationship “R” stores information about triples of books, authors and editors such that an author writes a book with an editor. Diagram (b) also captures the required information. For example, • if editors e1 and e2 both edit book b1 • if author a1 writes book b1 • if author a1 works with editor e1 and e2 we can infer that b1 is written by a1 and edited by e1 . We can also infer that b1 is written by a1 and edited by e2 . Note: suppose that the relation between “Editor” and “Books” is “Can Edit”, • if editors e1 and e2 both can edit book b1 3 • if author a1 writes book b1 • if author a1 works with editor e1 and e2 we are not able to infer from this if b1 , written by a1 , is edited by e1 or by e2 . Thus, in this case, the information cannot be captured in both diagrams. (b) Suppose that each book is edited by at most one editor. Can you add edge constraints (arrows) to the diagram on the left in order to capture this information? What about the diagram on right? Explain. We cannot add an edge to diagram (a) to capture this information. If we add an arrow from “Books” to “R” then this implies that each book is edited by at most one editor and written by at most one author, which is not part of the assumption. On the diagram (b), we can add an arrow from “Books” to “Edits”, to correctly capture the information. 2. What is wrong with using the following diagram to model the information? Writes Authors aid Books bid eid This diagram implies that each book written by an author, is edited by at most one editor. This is because a given pair of author and book can participate at most once in the relationship “Writes”. Problem 4 (40 Points) Congratulations! You have gotten a job planning databases for the European Union. Your first on job assignment is to help the various countries maintain information about their inhabitants. Your model should capture the following information: • In each country, there are provinces, which contain towns. There cannot be two provinces with the same name in a single country. Similarly, there cannot be two towns with the same name in a single province. • People live in towns. Men and women work in a town. Children learn in a school in a town. • A person can be a man, a woman, or a child, and has a first-name, last-name, id, and birthday. Children are any people under the age of 18. • A man can be married to a woman (polygamy is not allowed, i.e., one man can be married only to one woman). Although the Pope strongly disapproves, divorce, and subsequent remarriage, is possible. 4 • For each marriage, store the date of the marriage and information about who are the children of the married couple. You should assume that the parents of a child were married at the time of his birth. Draw an entity relationship diagram to model the information described above. Remember to put edge constraints (arrows) and participation constraints (thick lines) where needed. Underline the key attributes of each entity in the diagram. If you use the ISA relationship, state any covering and overlap constraints that hold. Make any necessary and logical assumptions. State any such assumptions clearly. If there are any constraints in the problem that could not be expressed in the diagram, state these clearly. Here is a possible solution. In our solution, the assumption that “divorce, and subsequent remarriage, is possible”, is not captured. Woman and Man cover adult and do not overlap. Same for Adult and Child. Each child is a son of exactly one pair of parents and learns in exactly one town.There is at least one province in each country and at least one town in each province. country name firstname in birthday lastname id province name people live in ISA work town name adult ISA child Child of learn date man Married to 5 woman