You are on page 1of 5

Selected exercises Chapter 3, Elmasri & Navathe

CHAPTER 3: DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL


Answers to Selected Exercises 3.16 Consider the following set of requirements for a university database that is used to keep track of students' transcripts. This is similar but not identical to the database shown in Figure 1.2: (a) The university keeps track of each student's name, student number, social security number, current address and phone, permanent address and phone, birthdate, sex, class (freshman, sophomore, ..., graduate), major department, minor department (if any), and degree program (B.A., B.S., ..., Ph.D.). Some user applications need to refer to the city, state, and zip of the student's permanent address, and to the student's last name. Both social security number and student number have unique values for each student. (b) Each department is described by a name, department code, office number, office phone, and college. Both name and code have unique values for each department. (c) Each course has a course name, description, course number, number of semester hours, level, and offering department. The value of course number is unique for each course. (d) Each section has an instructor, semester, year, course, and section number. The section number distinguishes different sections of the same course that are taught during the same semester/year; its values are 1, 2, 3, ...; up to the number of sections taught during each semester. (e) A grade report has a student, section, letter grade, and numeric grade (0, 1, 2, 3, 4 for F, D, C, B, A, respectively). Design an ER schema for this application, and draw an ER diagram for that schema. Specify key attributes of each entity type and structural constraints on each relationship type. Note any unspecified requirements, and make appropriate assumptions to make the specification complete. Answer:
STEP 1. Identify Enitities: STUDENT DEPARTMENT COURSE SECTION (in Dutch JAARGANG), note that this is a weak entity, having COURSE as owner. GRADE STEP2: Identify Relations: MAJOR-DEPARTMENT MINOR-DEPARTMENT : STUDENT DEPARTMENT : STUDENT DEPARTMENT : DEPARTMENT COURSE : COURSE SECTION : STUDENT SECTION GRADE

STEP 3: Identify Attributes (not made explicit here)

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Selected exercises Chapter 3, Elmasri & Navathe

REMARKS (BY SK): The entity GRADE may be left-out, in which case its attributes have to be added to the ternary relation STUD_SECT. However, in the description it is mentioned that there is a grade report in our Universe of Dicsourse, which motivated us to introduce the entity GRADE. Suppose that the description was: if a student follows a section, the final grade (some number) must be recorded, (so, without mentioning any grade report), then we could have left out the GRADE section. We will continue this discussion below. The structural constraints that are given here are WRONG, for which I apologize. Take for example the MAJOR_DEPT relation between a STUDENT and a DEPARTMENT. A student must participate in exactly one such relation instance, leading to a (min,max) structural constraint of (1,1). A DEPARTMENT may participate in an arbitrary number of relation instances (we do not have a lowerbound here, neither do we have an upperbound), leading to a (min,max) structural constraint of (0,N). The structural constraints of MAJOR_DEPT is therefore: STUDENT (1,1) -- MAJOR_DEPT (0,N) DEPARTMENT. A complete list of structural constraints is: o o o As discussed above: STUDENT (1,1) -- MAJOR_DEPT (0,N) DEPARTMENT A student may not have a minor department: STUDENT (0,1) -- MINOR_DEPT (0,N) DEPARTMENT A course must be associated to a department, a department may have an arbitrary number of courses:

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Selected exercises Chapter 3, Elmasri & Navathe

DEPARTMENT --(0,N) DEPT_COURSE (1,1) -- COURSE A section must be associated to a course, a course may have an arbitrary number of sections: COURSE (0,N) COURSE_SECT (1,1) -- SECTION o A section may have arbitrary students, a student may attend arbitrary sections, a certain grade may be assigned to an arbitrary number of students: STUD_SECT (0,N) SECTION (0,N) STUDENT (0,N) GRADE (Here, we have given the relation name STUD_SECT first, because it is a ternay relation.) Actually, I was confused myself with the structural constraints of the last relation STUD_SECT. My intuition said that a grade report belongs to exactly one STUDENTSECTION pair, so initially I had: STUD_SECT (0,N) SECTION (0,N) STUDENT (1,1) GRADE The point is that in our ER-model (which comes with the book) there is an entity GRADE, and not an entity GRADE_REPORT which would have been more in-line with the initial description. So, personally I prefer to model a weak entity GRADE-REPORT with two owners, STUDENT and SECTION. o

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Selected exercises Chapter 3, Elmasri & Navathe

3.17 Composite and multi-valued attributes can be nested to any number of levels. Suppose we want to design an attribute for a STUDENT entity type to keep track of previous college education. Such an attribute will have one entry for each college previously attended, and this entry is composed of: college name, start and end dates, degree entries (degrees awarded at that college, if any), and transcript entries (courses completed at that college, if any). Each degree entry is formed of degree name and the month and year it was awarded, and each transcript entry is formed of a course name, semester, year, and grade. Design an attribute to hold this information. Use the conventions of Figure 3.5. Answer: { PreviousEducation ( CollegeName, StartDate, EndDate, { Degree (DegreeName, Month, Year) }, { Transcript (CourseName, Semester, Year, Grade) } ) } Note (background information, not essential for examination): Note that in Computer Science we usually denote such nested structures in the BNF notation for defining grammars: PreviousEducationList:: PreviousEducation* PreviousEducation: CollegeName StartDate EndDate Degree* Transcript* Degree : DegreeName Month Year Transcript : CourseName Semester Year Grade

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

Selected exercises Chapter 3, Elmasri & Navathe

3.18 Show an alternative design for the attribute described in Exercise 3.17 that uses only entity types (including weak entity types if needed) and relationship types. Answer: This example illustrates a perceived weakness of the ER model, which is: how does the database designer decide what to model as an entity type and what to model as a relationship type. In our solution, we created a weak entity type ATTENDANCE; each (weak) entity in ATTENDANCE represents a period in which a STUDENT attended a particular COLLEGE, and is identified by the STUDENT and the StartDate of the period. Hence, the StartDate attribute is the partial key of ATTENDANCE. Each ATTENDANCE entity is related to one COLLEGE and zero or more DEGREEs (the degrees awarded during that attendance period). The TRANSCRIPT of the STUDENT during each attendance period is modeled as a weak entity type, which gives the records of the student during the attendance period. Each (weak) entity in TRANSCRIPT gives the record of the sudent in one course during the attendance period, as shown in the ER diagram below. Other ER schema designs are also possible for this problem.

This material has been taken from draft Pre-Publication Material, Copyright AWL2004

You might also like