1 Data Modeling 2 Data Modeling Page 47 Process of creating a logical representation of the structure of the database The most important task in database development E-R Model Semantic Object Model Relational Model 3 Entity Relationship Data Model 4 Entity-Relationship Data Model Explicitly represents entities and their relationships Implementation independent For use at the conceptual and external levels Peter Pin-San Chen, The entity-relationship model---toward a unified view of data. ACM Transactions on Database Systems, Vol.1, No. 1, March 1976 - portal.acm.org 5 A picture with Peter Chen, the founder of E-R model 6 Entity-Relationship Data Model Entity Attribute Characteristic or property of an entity Relationship A thing, event, or person in the organization's environment about which someone wants to collect data Association between entities Composite entity (Associative entity) Represents both an entity and relationship Has its own properties 7 Components of E-R Model Entity Relationship Composite entity Attribute 8 An E-R Model for Student Registration System Entities Course Instructor Student 9 An E-R Model for Student Registration System Relationships One-to-many Course Teaches M Instructor 1 N 1 Advises M Course Enrollment Student M Many-to-many 10 An E-R Model for Student Registration System Course Teaches M Instructor 1 1 1 Advises M M Student Class Enrollment 1 M Composite Entity 11 An E-R Model for Student Registration System Course Number Instructor ID Description Room Course Attributes Rank Teaches M Name Instructor 1 1 1 Advises M M Student Class Enrollment M Course Number Grade Student Number 1 Student Number Major Student Name 12 Entities “something that users track” Page 49 Figure 3-1 © 2000 Prentice Hall Attributes (properties) “describe the entity’s characteristics” Entity:Employee Attributes:EmployeeName, Extension, DateOfHire, JobSkillCode Attribute type Key attribute or identifier (i.e. employee number) Single value attribute (i.e. spouse) Multivalued attribute (i.e. children) Derived attribute (i.e. tax payment) Page 50 14 More about Entities Existence Dependency The existence of one entity depends on the existence of one or more other entities Fundamental entity vs. Attributive entity or Weak entity A weak entity is one that is existence-dependent and has a primary key that is partially or totally derived from the parent entity in the relationship. Entity Supertypes and Subtypes Exclusive (disjoint) and Inclusive (overlapping) Covering and non-covering 15 Subtype Entities “an entity that contains option sets of attributes” Page 56 Figure 3-10b © 2000 Prentice Hall Relationships A relationship is an association between entities. A unary relationship exists when an association is maintained within a single entity. (Recursive relationship) A binary relationship exists when two entities are associated. (Most common) A ternary relationship exists when three entities are associated. (e.g. real estate sales: buyer, seller, and property) 17 Classroom Assignment Course 1 M Classroom Assignment Classroom M 1 M 1 Time Slots Convert a ternary relationship to three binary relationships 18 Relationships “associations between entities” Page 51 Figure 3-3 © 2000 Prentice Hall Connectivity and Cardinality The term connectivity is used to describe the relationship classification (e.g., one-to-one, one-to-many, and many-to-many). Cardinality expresses the specific number of entity occurrences associated with one occurrence of the related entity. Relational Participation: Optional, Mandatory The actual number of associated entities is usually a function of an organization’s policy. 20 Connectivity and Cardinality Connectivity Professor 1 M teaches (0,3) Course (1,1) Optional entity Mandatory entity Cardinality 21 Building E-R Model Understand business rules and assumptions Identify entities Identify relationships Identify attributes Check and improve E-R model Convert E-R model to relational tables 22 Business rules A business rule is a statement that defines or constrains some aspect of the business. Business rules and policies govern creating, updating, and removing data in an information processing and storage system. 23 Example of business rules A student can take up to five courses each term Each course will be taught by only one teacher A customer must use valid credit card to make online payment A flower order can deliver to anywhere in North America but only one location 24 Business rules As a database analyst, you need to: Identify and understand those rules that govern data Represent those rules so that they can be unambiguously understood Implement those rules in database technology 25 Sales Order Form 26 An E-R Model for Order Processing: Order Number Date S ID S Name Product Number Customer Name Orders Description Address Unit price Quantity Total 27 An E-R Model for Order Processing: Entities Customer Products Salesman Orders 28 An E-R Model for Order Processing: Relationships Customer Products Salesman 1 1 1 Prepared Placed M OrderLine M Orders M 1 M 29 An E-R Model for Order Processing: Attributes Customer Name Description Unit price S Name S ID Address Customer Product Number Products Salesman 1 1 1 Prepared Placed M OrderLine M Orders M 1 M S ID Product Number Quantity Order Number Order Number Customer Name Date 30 Crow's Foot Notation of E-R Diagram with Attributes Shown 31 Cardinality Symbols of Relationships for ERD Check and improve E-R model Convert a multivalued attribute into an attribute entity or weak entity Introduce composite entity to convert a m:n relation into two 1:m relations. Introduce a composite key 33 Check and improve E-R model Each entity must have a key (simple or composite) Make each attribute associate with only one entity unless it is a foreign key Make each entity represent a simple object or concept Divide complex entity into several related simple entities 34 Example:A Construction Company A manager may manage many projects. Each project requires the services of many employees. An employee may be assigned to several different projects. Some employees are not assigned to a project and perform duties not specifically related to a project. Some employees are part of a labor pool, to be shared by all project teams. Each employee has a (single) primary job classification. This job classification determines the hourly billing rate. Many employees can have the same job classification. 35 A E-R Model for A Construction Company Project Employee Assignment Job class 36 A E-R Model for A Construction Company Subclass Manager Project Worker Employee Assignment Job class 37 A E-R Model for A Construction Company Project M 1 Manages 1 1 M Assignment Employee M Has M 1 Job class 38 A E-R Model for A Construction Company Project Number Project name Project Manager ID M 1 Manages 1 Employee 1 M Assignment Employee Name Employee Number Hire Date M Has M 1 Job class Assignment Number Hour Rate Hours Project Number Employee Number Job Code Job Description 39 The Semantic Object Model 40 Semantic Object Model E. F. Codd, “Extending the Relational Model to Capture More Meaning,” ACM Transactions on Database Systems, Dec. 1976, pp. 397-424. Micheal Hammer and Dennis McLeod, “Database Description with SDM: A Semantic Database Model,” ACM Transactions on Database Systems, Setp. 1981, pp 351-386. 41 Semantic Objects “a named collection of attributes that sufficiently describes a distinct entity” Student Customer Employee Page 74 42 Attributes “define the characteristics of semantic objects” Page 75 Figure 4-2a © 2000 Prentice Hall 43 Attribute Cardinality “indicates the minimum or maximum number of instances of the attribute that must exist in order for the object to be valid” Page 76 Figure 4-2b © 2000 Prentice Hall 44 Object Instances “the occurrence of a particular semantic object” Page 77 Figure 4-3 © 2000 Prentice Hall 45 Object Identifier “one or more object attributes that the users employ to identify object instances” Example: CustomerID for Customer Page 78 46 Domain “a description of an attribute’s possible values” Page 78 47 Semantic Object View “the portion of an object that is visible to a particular application; view” Page 79 Figure 4-4 © 2000 Prentice Hall 48 Highline University Administration Database Objects: College Department Professor Student Page 80 49 Semantic Object Diagrams Page 85 Figure 4-13 (1) © 2000 Prentice Hall 50 Semantic Object Diagrams Page 85 Figure 4-13 (2) © 2000 Prentice Hall 51 Semantic Object Diagrams Page 85 Figure 4-13 (3) © 2000 Prentice Hall 52 Semantic Object Diagrams Page 85 Figure 4-13 (4) © 2000 Prentice Hall 53 Sales Order Form 54 Semantic vs. E-R Model Page 105 Figure 4-34 © 2000 Prentice Hall 55 Semantic vs. E-R Model Page 105 Figure 4-33 © 2000 Prentice Hall 56