Download presentation
1
Entity-Relationship Model
Chapter 2 Entity-Relationship Model Chapter 11 & 12 in Textbook
2
Database Design Steps in building a database for an application: 1. Understand real-world domain being captured. 2. Specify it using a database conceptual model (E/R,OO). 3. Translate specification to model of DBMS (relational). 4. Create schema using DBMS commands (DDL). 5. Load data (DML). Real-world domain Conceptual model DBMS data model Create Schema (DDL) Load data (DML) ER Model
3
Entity-Relationship Model (E/R)
A picture is worth a thousand words The Entity-Relationship model (ER) is a high-level description of the structure of the DB. The Entity-Relationship Diagram (ERD) is a graphical model for representing the conceptual model for the data. A E/R models the DB using three element types: - Entities - Attributes - Relationships ER Model
4
ERD Example name number DOB dean of operate chairs advise teach offer
PROFESSOR number SCHOOL 1 DOB 1 1 1 1 (0,1) (1,1) (0,1) dean of (0,4) (0,*) 1 (1,*) operate (1,1) chairs (0,*) M advise teach DEPARTMENT 1 (1,1) 1 (1,*) (1,*) 1 offer (1,1) (1,1) M M (1,1) M N M M 1 enroll-in CLASS belong-to COURSE STUDENT (0,*) (0,*) (1,1) (0,*) (1,1) M code hrs has
5
Entities & Entity Type Entity is an object that exists and is distinguishable from other objects. e.g. person, company, course, university Entity Type is a set of entities of the same type that share the same properties. e.g. set of all persons, companies, trees, courses STUDENT COURSE ER Model
6
Relationships & Relationship Types
A relationship associates 2 or more entities. A relationship type is a set of associations between entity types. STUDENT study COURSE S r CO1 S r CO2 S r3 study STUDENT COURSE ER Model
7
Degree of Relationship Type
Degree of relationship refers to number of participating entity types in a relationship. A relationship of degree two (2 entity types) are binary. A relationship of degree three (3 entity types) are ternary. ER Model
8
Degree of Relationship Type
A relationship of degree two (2 entity types) are binary. study STUDENT COURSE ER Model
9
Degree of Relationship Type
A relationship of degree three (3 entity types) are ternary. e.g. registration of a student in a course by a staff. register STUDENT COURSE STAFF ER Model
10
Recursive Relationship
Recursive relationship is a relationship type where the same entity type participates more than once in a different role. It is a unary relationship. COURSE STUDENT require lead ER Model
11
Roles Role indicates the purpose that each participating entity type plays in a relationship. (e.g. prerequisite, requester) COURSE STUDENT requester prerequisite leader member require lead ER Model
12
Roles Role can be used when two entities are associated through more than one relationship to classify the purpose of each relationship. manages Manager Branch office BRANCH STAFF Branch office Staff member allocated ER Model
13
Attributes Attributes are descriptive properties for an entity type or a relationship type. All entities in one entity type have the same attributes. name DOB St_no Tel_no STUDENT ER Model
14
Attributes of Entities
name DOB name hours St_no number Tel_no study STUDENT COURSE ER Model
15
Attributes of Relationships
Start End Object Employee Company contract All relationships in one relationship type have the same attributes. Relationships can be distinguished not only by their attributes but also by their participating entities. ER Model
16
Simple & Composite Attributes
Simple attribute is an attribute that have a single value with an independent existence. e.g. salary, age, gender,... ER Model
17
Single-valued & Multi-valued Attributes
Multi-valued attribute is an attribute that may hold multiple values, of the same type, for a single entity. e.g. tel_no, degrees,… initial FName LName Area_cd name DOB no St_no Tel_no EX STUDENT ER Model
18
Simple & Composite Attributes
Composite attribute is an attribute composed of multiple distinct components, each with an independent existence. e.g. address (street, area, city, post code) name (First name, initial, Last name) phone no. (area code, number, exchange no) initial FName LName Area_cd name DOB no St_no Tel_no EX STUDENT ER Model
19
Single-valued & Multi-valued Attributes
Single-valued attribute is an attribute that holds a single value for a single entity. It is not necessarily a simple attribute. e.g. student_no, age, gender,... ER Model
20
Derived Attributes Derived attribute is an attribute that represents a value that is derived from the value of a related attribute,not necessarily in the same entity type. e.g. age is derived from date_of_birth total_cost is derived from quantity*unit_price name DOB St_no Tel_no age STUDENT ER Model
21
Keys Candidate key (CK) is the minimal set of attributes that uniquely identifies an entity. It cannot contain null. e.g. student_no, social_security_no, branch_no… Primary Key (PK) is a candidate key that is selected to uniquely identify each entity. Alternate Key (AK) is a candidate key that is NOT selected to be the primary key. ER Model
22
Keys Example ELEMENT(symbol, name, atomic_no) ER Model
23
Keys Example Candidate Key ELEMENT(symbol, name, atomic_no)
Primary Key Alternate Keys ER Model
24
Choice of PK Choice of Primary Key (PK) is based on: Attribute length
Number of attributes required Certainty of uniqueness ER Model
25
Primary Key in ERD STUDENT initial FName LName Area_cd name DOB no
St_no Tel_no EX STUDENT age ER Model
26
Keys A key can be: - simple key is a candidate key of one attribute.
e.g. student_no, branch_no… - composite key is a candidate key that consists of two or more attributes. e.g. STUDENT (Lname, Fname, Init) CLASS (crs_code, section_no) ADVERT (property_no, newspaperName, dateAdvert) ER Model
27
Composite Key in ERD name Section_no hours crs_code CLASS ER Model
28
Strong & Weak Entity Types
A strong entity type is NOT existence-dependent on some other entity type. It has a PK. A weak entity type is an entity type that is existence-dependent on some other entity type. It does not have a PK. ER Model
29
Weak Entity Type The existence of a weak entity type depends on the existence of a strong entity set; it must relate to the strong entity type via a relationship type called identifying relationship. The PK of a weak entity set is formed by the PK of its strong entity type, plus a weak entity type discriminator attribute. LName FName dep_no FName emp_no DOB has EMPLOYEE DEPENDENT ER Model
30
Cardinalities Cardinality ratio expresses the number of relationships an entity can participate in. Most useful in describing binary relationship types. For a binary relationship type the mapping cardinality must be one of the following types: – One to one (1:1) – One to many(1:M) – Many to one (M:1) – Many to many (M:N) ER Model
31
One-To-One Relationship
PROFESSOR chair DEPARTMENT P1 r D002 P2 P3 r2 D001 1 1 chairs PROFESSOR DEPARTMENT A professor chairs at most one department; and a department is chaired by only one professor. ER Model
32
One-To-Many Relationship
PROFESSOR teach COURSE P1 r C01 r2 C02 P2 r3 C03 P C04 1 M teach PROFESSOR COURSE A course is taught by at most one professor; a professor teaches many courses. ER Model
33
Many-To-One Relationship
CLASS require ROOM C r R001 C r R002 C r R003 R004 M 1 require CLASS ROOM A class requires one room; while a room can be scheduled for many classes. ER Model
34
Many-To-Many Relationship
CLASS enroll STUDENT C r S1 C r S3 C r S4 r S5 M N enroll CLASS STUDENT A class enrolls many students; and each student is enrolled in many classes. ER Model
35
Multiplicity Multiplicity is the number (range) of possible entities that may relate to a single association through a particular relationship. It is best determined using sample data. Takes the form (min#, max#) ER Model
36
Multiplicity STAFF manage BRANCH SG1 r1 B002 SG2 SG3 r2 B001 1 1
(0,1) (1,1) ER Model
37
Multiplicity STAFF oversee PROPERTY SG1 r1 P1 r2 P2 SG2 r3 P14 SG3 P6
(0,10) (0,*) (0,1) ER Model
38
Multiplicity Newspaper advertise PROPERTY Al-Riyadh r1 P1 r2 P13 Al-Bilad r3 Al-Madinah r4 P6 Al-Sharq P4 M N advertise NEWSPAPER PROPERTY (0,*) (0,*) ER Model
39
Participation Constraints
Participation constraints determine whether all or only some entities participate in a relationship. Two types of participation: - Mandatory (total) - Optional (partial) ER Model
40
Participation Constraints
Mandatory (total) (1:*): if an entity’s existence requires the existence of an associated entity in a particular relationship (existence-dependent). e.g. CLASS taught-by PROFESSOR i.e. CLASS is a total participator in the relation. A weak entity always has a mandatory participation constraints but the opposite not always true. ER Model
41
Participation Constraints
Optional (partial) (0:*): if an entity’s existence does not require a corresponding entity in a particular relationship. (Not existence-dependent). e.g. PROFESSOR teach CLASS i.e. PROFESSOR is a partial participator in the relation. ER Model
42
From Chen Notation to Crow’s Foot Notation
ER Model
43
Chen Notation EntityName Verb Phrase AttributeName
44
Crow’s Foot Notation Acceptable Entity Attribute Relationship
EntityName EntityName Verb phrase List of Attributes Acceptable
45
ER diagram of Staff and Branch entities and their attributes
Pearson Education © 2009
46
Strong entity type called Client and weak entity type called Preference
Pearson Education © 2009
47
Relationship called Advertises with attributes
Pearson Education © 2009
48
Multiplicity of ternary Registers relationship
Pearson Education © 2009
49
Chen Model Crow’s Foot Cardinality 1 to represent one.
M to represent many Crow’s Foot 1 M
50
Binary Relationships The 1: M relationship between PAINTER and PAINTING
51
The 1:1 Relationship Between PROFESSOR and DEPARTMENT
52
The M:N Relationship Between STUDENT and CLASS
53
Mandatory vs. Optional Cardinalities
Specifies whether an instance must exist or can be absent in the relationship Lecturer Class handles A Lecturer may handle zero or many classes. A class is handled by one and only one Lecturer. Optional Mandatory (0,*) (1,1) 1 M
54
Multiplicity as cardinality and participation constraints
Pearson Education © 2009
55
ERD Mistakes ER Model
56
Problems with ER Models
Problems may arise when designing a conceptual data model called connection traps. Often due to a misinterpretation of the meaning of certain relationships. Two main types of connection traps are called fan traps and chasm traps. Pearson Education © 2009
57
Problems with ER Models
Fan Trap Where a model represents a relationship between entity types, but pathway between certain entity occurrences is ambiguous. Chasm Trap Where a model suggests the existence of a relationship between entity types, but pathway does not exist between certain entity occurrences. Pearson Education © 2009
58
An Example of a Fan Trap Pearson Education © 2009
59
Semantic Net of ER Model with Fan Trap
At which branch office does staff number SG37 work? Pearson Education © 2009
60
Restructuring ER model to remove Fan Trap
Pearson Education © 2009
61
Semantic Net of Restructured ER Model with Fan Trap Removed
SG37 works at branch B003. Pearson Education © 2009
62
An Example of a Chasm Trap
Pearson Education © 2009
63
Semantic Net of ER Model with Chasm Trap
At which branch office is property PA14 available? Pearson Education © 2009
64
ER Model restructured to remove Chasm Trap
Pearson Education © 2009
65
Semantic Net of Restructured ER Model with Chasm Trap Removed
Pearson Education © 2009
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.