========================================================================= LECTURE NOTES - ENTITY-RELATIONSHIP MODEL ========================================================================= Database Design --------------- Steps in building a database for an application: 1. Understand real-world domain being captured 2. Specify it using a database design model 3. Translate specification to model of DBMS 4. Create schema using DBMS commands (DDL) 5. Load data Real-world domain to Design data model (entity-relationship E/R, object-oriented OO) to DBMS data model (relational, object-relational, OO) - Design-to-DBMS step may be automated (e.g., E/R to relational) - Middle stage sometimes skipped: directly to relational model Real-world domain in book: movies Real-world domain for lectures: UC admissions Real-world domain for programming project: you pick Entity-Relationship (E/R) Model ------------------------------- - Historically very popular - "Watered down" object-oriented design model - Graphical - Not implemented by any DBMS ENTITY SETS: Like classes Set of ENTITIES (objects) Entities have ATTRIBUTES Can informally think of entities as records (Will formalize after studying relational model) KEYS: no two entities may agree on all key attributes - Underline - We will require keys on all entity sets No good way to notate multiple keys (sorry) RELATIONSHIP SETS: tie together entities from different entity sets RELATIONSHIP: one element of a relationship set (Distinction is not made clearly in the textbook) Think of relationship as connection between entities, or as a record -> Not all entities need to participate in relationships. Relationships can have ATTRIBUTES MULTIPLICITY of relationships (entity sets E1 and E2) (1) ONE-ONE: Each entity in E1 is related to at most one entity in E2 and vice-versa Q: Examples from application? (2) MANY-ONE: Each entity in E1 is related to at most one entity in E2 (converse is ONE-MANY) Q: Examples from application? (3) MANY-MANY: Each entity in E1 may be related to 0 or more entities in E2 and vice-versa Q: Examples from application? Relationship set involving only one entity set May have ROLES MULTIWAY RELATIONSHIP SETS How about MULTIPLICITY? Formal meaning of arrow pointing to entity set E in multiway relationship: pick one entity from each other set, together they must be related to at most one entity in E Q: What if we also have an arrow to Campuses? Q: What if we have an arrow to High Schools only? Could use binary relationships instead: Q: Advantages and disadvantages of this design? WEAK ENTITY SET: Entity set without its own key Weak entity sets must have relationship with a strong entity set, called WEAK RELATIONSHIP SET. Requirements on weak relationship set: - Must be many-one or one-one from weak to strong entity sets - All weak entities must participate in relationship "Value" of weak entity is attributes + key for related strong entity set Key for weak entity set is key for related strong entity set + any underlined attributes Weak relationship sets cannot have attributes Q: What if we want date attribute? ** In general, a weak entity set may have (weak) relationships with several strong entity sets; values and keys for weak entities are constructed from all of the strong entity sets together. ** In reality, the connected strong entity sets don't have to be strong, they just have to have keys. Q: Example requiring multiple connected strong entity sets? "SUBCLASSES" in E/R - Can think of objects as being constructed from multiple entities connected by Is-a relationships - Is-a relationships are one-one implicitly Summary of E/R Model ------------------- - Entity sets with attributes and keys - Relationship sets with attributes - Multiplicity of relationship sets - Roles - Multiway relationship sets - Weak entity sets - "Is-a" relationships