DATA MODELING AND ENTITY-RELATIONSHIP MODEL II IST 210: Organization of Data IST210 1
Developing an E-R Diagram: Outline 1. Draw Entities Define Attributes Define Identifier 2. Define the relationships Maximum cardinality: One or Many (1:1, 1:N, N:M) Minimum cardinality: Mandatory or Optional 3. Verify and refine IST210 2
Entity-Relationship Diagram IST210 3 UserID Video ID Name Address USER VIDEO Title Description Length Entity Name Attributes Identifier Minimum cardinality MandatoryOptional Maximum cardinality OneMany
Maximum Cardinality: Exercise IST210 4 BUILDINGAPARTMENT BUILDINGAPARTMENT BUILDINGAPARTMENT BUILDINGAPARTMENT Which design is most suitable? (A) (B) (C) (D) has OneMany
Minimum Cardinality: Exercise IST210 5 BUILDINGAPARTMENT BUILDINGAPARTMENT BUILDINGAPARTMENT BUILDINGAPARTMENT Which design is most suitable? (A) (B) (C) (D) has MandatoryOptional
LISA’S BOOKSTORE Case study IST210 6
Case Study: Lisa’s Bookstore (1) IST210 7 You are helping Lisa maintain information of her bookstore. A book contains information about book title, publisher, author names, and publication year. For a publisher, store the information about name, location, phone number. An author’s name and country should be stored in the database.
IST210 8 Draw Entities
IST210 9 BOOKID Title Year Publisher AuthorID Name Country PublisherName Location Phone BOOK AUTHOR PUBLISHER Draw Entities
IST BOOKID Title Year Publisher AuthorID Name Country PublisherName Location Phone BOOK AUTHOR PUBLISHER Publisher and Author should NOT be the attributes of the book! Information of publisher and author for a book is captured by the relationships! Draw Entities
Attribute v.s. Foreign Key Please note that there is NO foreign key concept in E-R diagram. Do not make a foreign key as an attribute in the E-R diagram. For example, PublisherName should NOT be an attribute of the BOOK entity. Their relationship is currently represented by the line and the corresponding min/max cardinality. In Chapter 5, we will learn how to transform a E-R diagram to tables. At that point, some relationships might be transformed into foreign key. IST210 11
IST BOOKID Title Year AuthorID Name Country PublisherName Location Phone BOOK AUTHOR PUBLISHER Maximum cardinality
IST BOOKID Title Year AuthorID Name Country PublisherName Location Phone BOOK AUTHOR PUBLISHER Maximum cardinality
IST BOOKID Title Year AuthorID Name Country PublisherName Location Phone BOOK AUTHOR PUBLISHER Minimum cardinality
IST BOOKID Title Year AuthorID Name Country PublisherName Location Phone BOOK AUTHOR PUBLISHER Minimum cardinality
Case Study: Lisa Bookstore (2) IST A customer can be uniquely identified using his/her address. A customer has information about his/her name, phone number and home address. Lisa wants to track all the book purchases. Each purchase is made by one customer on one book. The price and date of the purchase will be stored in database. A customer may purchase many books or not purchase any book.
IST BOOKID Title Year AuthorID Name Country PublisherName Location Phone BOOK AUTHOR PUBLISHER Add New Entities
IST BOOKID Title Year BOOK PurchaseID Price Date PURCHASE AuthorID Name Country AUTHOR Address Name Address Phone CUSTOMER PublisherName Location Phone PUBLISHER Minimum cardinality Maximum cardinality
IST210 19
IST BOOKID Title Year BOOK AuthorID Name Country PublisherNam e Location Phone AUTHOR PUBLISHER Address Name Address Phone CUSTOMER PurchaseID Price Date PURCHASE
Case Study: Lisa Bookstore (3) IST In Lisa’s bookstore, there are some events organized to interact with the customers. Lisa wants to record the information of events, including event name, type, and date. She also wants to record which customers attend which events.
IST BOOKID Title Year BOOK AuthorID Name Country AUTHOR EventID Name Date Type EVENT Address Name Address Phone CUSTOMER PurchaseID Price Date PURCHASE PublisherName Location Phone PUBLISHER Minimum cardinality Maximum cardinality
IST210 23
IST BOOKID Title Year BOOK AuthorID Name Country AUTHOR EventID Name Date Type EVENT Complete E-R Diagram PurchaseID Price Date PURCHASE Address Name Address Phone CUSTOMER PublisherName Location Phone PUBLISHER
COURSE REGISTRATION SYSTEM Case study IST210 25
Case Study: Course Registration (1) IST You are helping Penn State create a course registration system. Store information about all students, including their student IDs, names, s, and their major departments (assuming student has at most one major department). The department should have information about department name, building name, and phone number.
IST Draw Entities
IST StudentID Name STUDENT DepartName Building Phone DEPARTMENT Minimum cardinality Maximum cardinality
IST StudentID Name STUDENT DepartName Building Phone DEPARTMENT
Case Study: Course Registration (2) IST A course should have information about course ID, course name, and instructor name. Students can take many courses and a course can be registered by many students. We also need to store the final grade for a student in a course.
IST StudentID Name STUDENT DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE Where should we put grade???
Attributes on Relationships? When you need to store some information about a relationship, the relationship should actually be designed as an entity. If we want to store the grades for the relationship between COURSE and STUDENT, we need to make GRADE as a separate entity. If we only want to store which student taking which course, we don’t need a separate entity to capture their relationship. IST210 32
IST StudentID Name STUDENT StudentID CourseID Grade GRADE DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE Minimum cardinality Maximum cardinality
IST210 34
IST StudentID Name STUDENT StudentID CourseID Grade GRADE DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE
Case Study: Course Registration (3) IST A course is offered by a department. We also want to store this information.
IST210 37
IST StudentID Name STUDENT StudentID CourseID Grade GRADE DepartName Building Phone DEPARTMENT Complete E-R Diagram CourseID CourseName Instructor COURSE
IST Reminder Next Thursday (Oct 21 st ) is a big day: Assignment 4 Due Report 2 Due