We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5
Entity Relationship Model
This chapter introduces the entity-relationship model in detail. The chapter
covers numerous features of the model, several of which can be omitted depending on the planned coverage of the course. Weak entity sets (Section 2.6), design constraints (Section 2.7.4) and aggregation (Section 2.7.5), and the corresponding subsections of Section 2.9 (Reduction of an E-R Schema to Tables) can be omitted if time is short. We recommend covering specialization (Section 2.7.1) at least in some detail, since it is an important concept for object-oriented databases (Chapter 8). The E-R model itself and E-R diagrams are used often in the text. It is important that students become comfortable with them. The E-R model is an excellent context for the introduction of students to the complexity of database design. For a given enterprise there are often a wide variety of E-R designs. Although some choices are arbitrary, it is often the case that one design is inherently superior to another. Several of the exercises illustrate this point. The evaluation of the goodness of an E-R design requires an understanding of the enterprise being modeled and the applications to be run. It is often possible to lead students into a debate of the relative merits of competing designs andthus illustrate by example thatunderstandingthe application is often the hardest part of database design. Considerable emphasis is placed on the construction of tables from E-R diagrams. This serves to build intuition for the discussion of the relational model in the subse quent chapters. It also serves to ground abstractconcepts of entities and relationships into the more concrete concepts of relations. Several other texts places this material along with the relational data model, rather than in the E-R model chapter. Our mo tivation for placing this material here is help students to appreciate how E-R data models get used in reality, while studying the E-R model rather than later on. The material on conversion of E-R diagrams to tables in the book is rather brief in some places, the book slides provide better coverage of details that have been left implicit in the book. 7 8 Chapter 2 Entity Relationship Model Changes from 3rd edition: In the fourth edition we have updated several examples, including ternary rela tions (employee, branch, job instead of customer, loan, branch) and aggregation (manages instead of loan-officer), to make them more realistic. We have also added more ex amples, for instance for specialization we use person, customer and employee as the main example, instead of account, checking-account and savings-account,whichalso makes the example more realistic. We have replaced the US centric social-security by the more global (and more realistic) customer-id and employee-id. Wehaveaddednotation tomakedisjointedness constraints and total participation explicit (overlapping and partial participation are the default). We have introduced alternative E-R notations since many real world applications use alternative nota tions. We have also provided a brief introduction to UML class diagrams, which are being used increasingly in place of E-R diagrams, in tools such as Oracle designer. Wehavedroppedcoverageofexistencedependenciessincetotalparticipationcon straints provide a very similar constraint. The distinction between total participation and existence dependencies is too minor to be of practical use, and only confuses students. Design issues are discussed in more detail. Exercises 9 address driver-id name model license person owns car year report-number location date driver participated damage-amount accident Figure 2.1 E-R diagram for a Car-insurance company. Exercises 2.1 Explain the distinctions among the terms primary key, candidate key, and su perkey. Answer: Asuperkey is a set of one or more attributes that, taken collectively, al lows us to identify uniquely an entity in the entity set. A superkey may contain extraneous attributes. If K is a superkey, then so is any superset of K.Asuperkey for which no proper subset is also a superkey is called a candidate key.Itispos sible that several distinct sets of attributes could serve as candidate keys. The primary key is one of the candidate keys that is chosen by the database designer as the principal means of identifying entities within an entity set. 2.2 Construct an E-R diagram for a car-insurance company whose customers own one or more cars each. Each car has associated with it zero to any number of recorded accidents. Answer: See Figure 2.1 2.3 Construct an E-R diagram for a hospital with a set of patients and a set of medi cal doctors. Associate with each patient a log of the various tests and examina tions conducted. Answer: See Figure 2.2 2.4 A university registrar’s office maintains data about the following entities: (a) courses, including number, title, credits, syllabus, and prerequisites; (b) course offerings, including coursenumber, year,semester,sectionnumber, instructor(s), timings, and classroom; (c) students, including student-id, name, and program; and (d) instructors, including identification number, name, department, and ti tle. Further, the enrollment of students in courses and grades awarded to stu dents in each course they are enrolled for must be appropriately modeled. Construct anE-Rdiagramfortheregistrar’soffice.Document allassumptions that you make about the mapping constraints. Answer: See Figure 2.3. In the answer given here, the main entity sets are student, course, course- offering, 10 Chapter 2 Entity Relationship Model insurance name ss# test−log test_id date−admitted date−checked−out patients test performed_by Dr−Patient doctors test_name sid student program name dss# date time result name Figure 2.2 E-R diagram for a hospital. time enrols grade syllabus secno course− offerings year is offered room teaches semester iid specialization name requires instructor dept courseno prerequisite maincourse course credits title Figure 2.3 E-R diagram for a university. title and instructor. The entity set course-offering is a weak entity set dependent on course. The assumptions made are : a. aclass meets only at one particular place and time. This E-R diagramcannot model a class meeting at different places at different times. b. There is no guarantee that the database does not have two classes meeting at the same place and time. 2.5 Consider a database used to record the marks that students get in different ex ams of different course offerings. Exercises 11 sid student name time takes secno course− room offerings program marks eid year semester exam name time place Figure 2.4 E-R diagram for marks database. courseno a. Construct an E-R diagram that models exams as entities, and uses a ternary relationship, for the above database. b. Construct an alternative E-R diagram that uses only a binary relationship between students and course-offerings. Make sure that only one relationship exists between a particular student and course-offering pair, yet you can represent the marks that a student gets in different exams of a course offer ing. Answer: a. See Figure 2.4 b. See Figure 2.5 2.6 Construct appropriate tables for each of the E-R diagrams in Exercises 2.2 to 2.4. Answer: a. Car insurance tables: person (driver-id, name, address) car (license,year,model) accident (report-number,date,location) participated(driver-id, license, report-number, damage-amount) b. Hospital tables: patients (patient-id, name, insurance, date-admitted, date-checked-out) doctors (doctor-id, name, specialization) test (testid, testname, date, time, result) doctor-patient (patient-id,doctor-id) test-log (testid,patient-id) performed-by (testid,doctor-id) 12 Chapter 2 Entity Relationship Model sid student program name marks time takes secno course− offerings year room semester examof exam name time place courseno Figure 2.5 Another E-R diagram for marks database. c. University registrar’s tables: student (student-id,name,program) course (courseno, title, syllabus, credits) course-offering (courseno,secno,year, semester, time, room) instructor (instructor-id, name, dept, title) enrols (student-id,courseno,secno, semester,year,grade) teaches (courseno,secno, semester,year, instructor-id) requires (maincourse, prerequisite) 2.7 Design an E-R diagramfor keeping track of the exploits of your favourite sports team.You shouldstorethematchesplayed,the scoresin eachmatch,theplayers in each match and individual player statistics for each match. Summary statis tics should be modeled as derived attributes. Answer: See Figure 2.6 2.8 Extend the E-R diagram of the previous question to track the same information for all teams in a league. Answer: See Figure 2.7 Note that a player can stay in only one team during a season. 2.9 Explain the difference between a weak and a strong entity set. Answer: A strong entity set has a primary key. All tuples in the set are distin guishable by that key. A weak entity set has no primary key unless attributes of the strong entity set on which it depends are included. Tuples in a weak entity set are partitioned according to their relationship with tuples in a strong entity