Chapter 4 Entity Relationship ER Modeling q The














































































- Slides: 78
Chapter 4 Entity Relationship (ER) Modeling q The ER Model q Developing and ER Diagram q Extended ER Model q Entity Integrity : Selecting Primary Key
In this chapter, you will learn: The main characteristics of entity relationship components How relationships between entities are defined and refined and how those relationships are incorporated into the database design process How ERD components affect database design and implementation That real-world database design often requires the reconciliation of conflicting goals Prepared by : Maizatul Akma bt Napiah 2 Chapter 3 | Entity Relationship (ER) Modeling
The Entity Relationship (ER) Model ER model forms the basis of an ER diagram ERD represents conceptual database as viewed by end user ERDs depict database’s main components: ◦ Entities ◦ Attributes ◦ Relationships 3 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Refers to entity set and not to single entity occurrence Corresponds to table and not to row in relational environment In both Chen and Crow’s Foot models, entity is represented by rectangle containing entity’s name Entity name, a noun, is usually written in capital letters Entities 4 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Characteristics of entities In Chen model, attributes are represented by ovals and are connected to entity rectangle with a line Each oval contains the name of attribute it represents In Crow’s Foot model, attributes are written in attribute box below entity rectangle Attributes 5 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Attributes (continued) 6 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Attributes have domain Domain is attribute’s set of possible values Attributes may share a domain a set of permitted values - ex) domain of customer--name : set of all text strings of a certain length Domains are the set of allowable data values for a Column. For example, the Five. Digit. Zip. Code Column on the customer entity can be in the integer domain. As such, the database would not allow you to place values like 123. 45 (floating point) or ABC (character) into that Column. Domains 7 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Identifiers (Primary Keys) Underlined in the ERD Key attributes are also underlined in frequently used table structure shorthand 8 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Primary Key Guidelines Attribute or combination of attributes that uniquely identifies entity instances in an entity set Main function is to uniquely identify an entity instance or row within a table Guarantee entity integrity, not to “describe” the entity 9 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Primary Key Guidelines (continued) 10 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Composite Primary Keys Primary keys ideally composed of only single attribute Possible to use a composite key Primary key composed of more than one attribute 11 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Composite Primary Keys (continued) 12 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
When to Use Composite Primary Keys Useful as identifiers of composite entities, where each primary key combination is allowed only once in M: N relationship ◦ Automatically provides benefit of ensuring that there cannot be duplicate values 13 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
When to Use Composite Primary Keys (continued) 14 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
When to Use Composite Primary Keys (continued) Useful as identifiers of weak entities, where weak entity has strong identifying relationship with parent entity ◦ Normally used to represent: A real-world object that is existent dependent on another real-world object A real-world object that is represented in data model as 15 two separate entities in strong identifying relationship Chapter 3 | Entity Prepared by : Maizatul Akma bt Napiah Relationship (ER) Modeling
Composite and Simple Attributes Composite attribute can be subdivided Simple attribute cannot be subdivided 16 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Single-value attribute can have only a single value Single-Valued Attributes 17 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Multivalued attributes can have many values Multivalued Attributes 18 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Multivalued Attributes (continued) 19 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Resolving Multivalued Attribute Problems Although conceptual model can handle M: N relationships and multivalued attributes, you should not implement them in relational DBMS ◦ Within original entity, create several new attributes, one for each of the original multivalued attribute’s components Can lead to major structural problems in table ◦ Create new entity composed of original multivalued attribute’s components 20 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Resolving Multivalued Attribute Problems (continued) 21 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Resolving Multivalued Attribute Problems (continued) 22 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Resolving Multivalued Attribute Problems (continued) 23 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Derived Attributes Attribute whose value may be calculated (derived) from other attributes Need not be physically stored within database Can be derived by using an algorithm 24 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Derived Attributes (continued) 25 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Derived Attributes (continued) 26 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Relationships Association between entities Participants are entities that participate in a relationship Relationships between entities always operate in both directions Relationship can be classified as 1: M Relationship classification is difficult to establish if know only one side of the relationship 27 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Connectivity and Cardinality Connectivity ◦ Used to describe the relationship classification Cardinality ◦ Expresses minimum and maximum number of entity occurrences associated with one occurrence of related entity Established by very concise statements known as business rules 28 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Connectivity and Cardinality (continued) 29 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Existence Dependence Existence dependence ◦ Exist in database only when it is associated with another related entity occurrence Existence independence ◦ Entity can exist apart from one or more related entities ◦ Sometimes refers to such an entity as strong or regular entity 30 Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah
Relationship Strength Weak (non-identifying) relationships Exists if PK of related entity does not contain PK component of parent entity Strong (Identifying) Relationships Exists when PK of related entity contains PK component of parent entity 31 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Weak (Non-Identifying) Relationships 32 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Weak (Non-Identifying) Relationships (continued) 33 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Strong (Identifying) Relationships 34 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Weak Entities Weak entity meets two conditions ◦ Existence-dependent Cannot exist without entity with which it has a relationship ◦ Has primary key that is partially or totally derived from parent entity in relationship Database designer usually determines whether an entity can be described as weak based on business rules 35 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Weak Entities (continued) 36 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Weak Entities (continued) 37 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Participation Optional participation ◦ One entity occurrence does not require corresponding entity occurrence in particular relationship Mandatory participation ◦ One entity occurrence requires corresponding entity occurrence in particular relationship 38 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Participation (continued) 39 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Participation (continued) 40 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Participation (continued) 41 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Participation (continued) 42 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Degree Indicates number of entities or participants associated with a relationship Unary relationship ◦ Association is maintained within single entity Binary relationship ◦ Two entities are associated Ternary relationship ◦ Three entities are associated 43 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Degree (continued) 44 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Relationship Degree (continued) 45 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Recursive Relationships Relationship can exist between occurrences of the same entity set Naturally found within unary relationship 46 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Recursive Relationships (continued) 47 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Recursive Relationships (continued) 48 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Recursive Relationships (continued) 49 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Recursive Relationships (continued) 50 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Recursive Relationships (continued) 51 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Recursive Relationships (continued) 52 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Composite Entities Also known as bridge entities Composed of primary keys of each of the entities to be connected May also contain additional attributes that play no role in connective process 53 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Composite Entities (continued) 54 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Composite Entities (continued) 55 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Composite Entities (continued) 56 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram Database design is iterative rather than linear or sequential process Iterative process Based on repetition of processes and procedures 57 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) Building an ERD usually involves the following activities: ◦ Create detailed narrative of organization’s description of ◦ ◦ ◦ 58 operations Identify business rules based on description of operations Identify main entities and relationships from business rules Develop initial ERD Identify attributes and primary keys that adequately describe entities Revise and review ERD Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developinag an ER Diagram (continued) Tiny College ◦ Tiny College is divided into several schools Each school is composed of several departments ◦ Each department may offer courses ◦ Each department may have many professors assigned to it ◦ Each professor may teach up to four classes; each class is section of course ◦ Student may enroll in several classes, but (s)he takes each class only once during any given enrollment period 59 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) Tiny College (continued) ◦ Each department has several students Each student has only a single major and is associated with a single department ◦ Each student has an advisor in his or her department Each advisor counsels several students ◦ The relationship between class is taught in a room and the room in the building 60 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 61 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 62 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 63 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 64 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) Chapter 3 | Entity Relationship (ER) Modeling Prepared by : Maizatul Akma bt Napiah 65
Developing an ER Diagram (continued) 66 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 67 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 68 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 69 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 70 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Developing an ER Diagram (continued) 71 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Data Modeling Checklist 72 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Summary Entity relationship (ER) model ◦ Uses ERD to represent conceptual database as viewed by end user ◦ ERM’s main components: Entities Relationships Attributes ◦ Includes connectivity and cardinality notations 73 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Summary (continued) Connectivities and cardinalities are based on business rules In ERM, M: N relationship is valid at conceptual level ERDs may be based on many different ERMs Database designers are often forced to make design compromises 74 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Summary Extended entity relationship (EER) model adds semantics to ER model via entity supertypes, subtypes, and clusters Specialization hierarchy depicts arrangement and relationships between entity supertypes and entity subtypes Inheritance allows an entity subtype to inherit attributes and relationships of supertype 75 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Summary (continued) Composite keys are useful to represent M: N relationships and weak (strong-identifying) entities 76 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Summary (continued) Surrogate primary keys are useful when there is no natural key that makes a suitable primary key In a 1: 1 relationship, place the PK of mandatory entity as foreign key in optional entity Time-variant data refers to data whose values change over time and whose requirements mandate that you keep a history of data changes 77 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling
Summary (continued) Data modeling checklist provides way for designer to check that the ERD meets set of minimum requirements 78 Prepared by : Maizatul Akma bt Napiah Chapter 3 | Entity Relationship (ER) Modeling