Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Database Modeling II We dont live in a world of reality, we live in a world of perceptions. J. Gerald Simmons.

Similar presentations


Presentation on theme: "Relational Database Modeling II We dont live in a world of reality, we live in a world of perceptions. J. Gerald Simmons."— Presentation transcript:

1 Relational Database Modeling II We dont live in a world of reality, we live in a world of perceptions. J. Gerald Simmons

2 Class Outline u Using the ER methodology and notation discussed last day, create a completed entity-relationship model for: l a simple library database l a simple university faculty database u What are weak entities? u What is a generalized hierarchy? u What are the strengths and weaknesses of the Entity-Relationship model?

3 Steps in Entity-Relationship Modeling 1. Identify entities 2. Identify relationships 3. Determine relationship type 4. Determine level of participation 5. Assign an identifier for each entity 6. Draw completed E-R diagram 7. Deduce a set of preliminary skeleton tables along with a proposed primary key for each table (using rules provided) 8. Develop a list of all attributes of interest (not already listed and systematically assign each to a table in such a way to achieve a 3NF design (i.e., no repeating groups, no partial dependencies, and no transitive dependencies)

4 E-R Method Example: Library Database u Step 1. Identify entity types PUBLISHERAUTHORBOOK u Step 2. Identify relationships AUTHORBOOK writes PUBLISHERBOOK publishe s

5 Library Database (contd) u Step 3. Determine relationship type. Ask: l Each book is written by how many authors? Each author writes how many books? Each book may be authored by zero (anonymous), one, or more than one author and each author may write zero, one, or more than one book. The relationship type is many-to-many or: AUTHORBOOK writes MN For PUBLISHER-publishes-BOOK, each publisher publishes zero, one, or more books and each book is published by exactly one publisher. The relationship type is one-to-many where BOOKS is on the many side and PUBLISHER is one the one side. PUBLISHERBOOK publishe s M1

6 Library Database (contd) u Step 4. Determine level of participation l Since each book does not have to be authored (anonymous) and since each author does not have to write a book (may make CD) the level of participation is optional for both sides of the relationship of AUTHOR-writes-BOOK combination AUTHORBOOK writes MN (0, N) 1N PUBLISHERBOOK publishe s l For the PUBLISHER-publishes-BOOK combination, the level of participation for PUBLISHER is optional (publishers do not necessarily have to publish a book, perhaps newsletters) and the level of participation for the BOOK side is mandatory (each book must have a publisher) (0, N)(1,1)

7 Library Database (contd) u Step 5. Assign an identifier for each entity l AuthorID, ISBN, PublisherID u Step 6. Draw completed E-R diagram PUBLISHER AUTHORBOOK writes publishes AuthorID,... ISBN,... PublisherID,... N 1 NM (0,N) (1,1) (0,N)

8 Library Database (contd) u Step 6. Draw completed E-R diagram - resolve M:N relationships AUTHORBOOK writes AuthorID,... ISBN,... M1 AuthorID,ISBN,... (0,N) PUBLISHER publishes PublisherID,... M 1 (1,1) (0,N) 1M (1,1)

9 E-R Modeling: University Example u A database is to be set up to record information about faculty, the courses they teach, and the students who take courses. Some courses are taught by teams of faculty members. l Step 1. Identify entity types STUDENTFACULTYCOURSE FACULTYCOURSE teaches STUDENTCOURSE takes l Step 2. Identify relationships

10 University Example (contd) u Step 3. Determine relationship type. Ask: –Each faculty member teaches how many courses? –Each course is taught by how many faculty? –Each student takes how many courses? –Each course is taken by how many students? l Use occurrences diagram to visualize relationship between entities F1C1F2C2F3C3F4C4F5C5F6C6F1C1F2C2F3C3F4C4F5C5F6C6 S1C1S2C2S3C3S4C4S5C5S6C6S1C1S2C2S3C3S4C4S5C5S6C6

11 University Example (contd) u Step 3. Determine Relationship type (contd) l For FACULTY-teaches-COURSE we are told each faculty member teaches zero, one, or two courses. We are told some courses are taught by zero, one, two, or three faculty. This is a many-to-many relationship. FACULTYCOURSE teaches MN l For STUDENT-takes-COURSE each student enrols in one to six courses and each course is taken by zero or up to 30 students. This too is a many-to-many relationship. STUDENTCOURSE takes MN

12 University Example (contd) u Step 4. Determine level of participation l FACULTY-teaches-COURSE - level of participation is optional, since sometimes Faculty do not have to teach (e.g., sabbatical); similarly, a course may not have anyone interested in teaching it FACULTYCOURSE MN FACULTYCOURSE teaches MN (0,2)(0,3) l STUDENT-takes-COURSE - level of participation is mandatory since students must take at least one course; a course, however, may or may not have students taking it STUDENTCOURSE takes NM (1,6)(0,30)

13 University Example (contd) u Step 5. Assign an identifier for each entity l FacultyID, CourseID, StudentID u Step 6. Draw completed E-R diagram COURSESTUDENT taken by CourseID,... StudentID,... FACULTY taught by FacultyID,... M N M N (0,30)(1,6) (0,2) (0,3)

14 University Example (contd) u You are now told that in addition to the relationships given, each student is assigned a faculty advisor who gives direction in choosing courses. u Use occurrences diagram to visualize relationship between entities u We are told each student is advised by exactly one faculty advisor. We can assume that each faculty member advises zero, one, or more students. This means the additional relationship is of type one-to- many or 1:M. u The STUDENT is on the many side of the relationship and must be advised therefore, faculty is mandatory to student; FACULTY on the one side of the relationship may or may not have a student, therefore student is optional to faculty. STUDENTFACULTY advises 1M (0,N)(1,1)

15 University Example (contd) u Step 6. Draw completed E-R diagram FACULTY COURSESTUDENT takes taught by CourseID,... StudentID,... FacultyID,... advise s 1 M 1 M 1 M (1,6)(0,30)(0,3) (0,2) (0,N) (1,1) M1 1 M

16 Weak Entities u an entity that has a dependency on the existence of another entity (mandatory participation) and u has a primary key that is partially or totally derived from the parent entity of the relationship u depict weak entity and relationship with rounded corners EMPLOYEE DEPENDENT EmployeeID,...EmployeeID, DependentID,... COURSESECTION CourseID,...CourseID, SectionID,... ` contains ` has a

17 Generalization Hierarchy u A subtype entity is an entity that contains a set of optional attributes of the supertype entity and inherits its attributes and its relationships from the supertype entity u If the supertype entity is related to exclusive (can belong to only one subtype) subtype entities, indicate with 1; if subtypes are overlapping (can belong to more than one), use m subtype supertype CLIENT INDIVIDUALCORPORATE The same identifier (e.g., ClientID) is used for the supertype as well as subtype. CONTRACT PRODUCTSSERVICES 1m

18 Evaluation of the E-R Model Using data models to conceptualize the design of a database saves time and money because a completed E-R diagram is the actual blueprint of the database. Its composition must reflect an organization's operations accurately if the database is to meet that organization's data requirements. u The completed E-R diagram also lets the designer communicate more precisely with those who commissioned the database design. Its easier to correct design flaws at the data modeling stage. u Do not confuse entities and relationships with actual tables. The transformation or decomposition of E-R models will be discussed within the next few weeks. u E-R modeling is an iterative process. Even when complete, ER models generally do not provide a complete picture (e.g., business rules cannot always be shown), therefore, much additional documentation is necessary.


Download ppt "Relational Database Modeling II We dont live in a world of reality, we live in a world of perceptions. J. Gerald Simmons."

Similar presentations


Ads by Google