Bcis5420 - Lecture Note - ch4 - ER Modleing
Bcis5420 - Lecture Note - ch4 - ER Modleing
Chapter 4
Copyright © 2019, 2016, 2013 Pearson Education, Inc. All Rights Reserved
2.1
Ch.4. Entity Relationship Modeling
Section. 1
2.2
Ch.4. Entity Relationship Modeling
2.3
Ch.4. Entity Relationship Modeling
Database Structure
Does the diagram below provide enough ideas about a database structure?
Database
AdventureWorks
Table Table
Sales.SalesOrderHeader Sales.SalesOrderDetail
Table
Sales.SalesOrderHeaderSalesReason
2.4
Ch.4. Entity Relationship Modeling
2.5
Ch.4. Entity Relationship Modeling
Clarification on Terminologies
2.6
Ch.4. Entity Relationship Modeling
Section. 2
Entities
2.7
Ch.4. Entity Relationship Modeling
• Entity
▪ Something that can be uniquely identified and the organization wishes to
maintain in data, such as person, place, or concept
▪ Can be either tangible (e.g., employee, students) or intangible (e.g., job
position, academic course)
▪ The title of an entity is generally for entity type (hence,
interchangeably used with entity type in the context of ER diagrams)
2.8
Ch.4. Entity Relationship Modeling
• Entity type: collection of entity (or entities) with attributes and hence, often
corresponding to a table (e.g., CUSTOMER)
• Entity instance: a specific example of an entity with some attributes,
corresponding to a row in a table (e.g., CID3)
2.9
Ch.4. Entity Relationship Modeling
2.10
Ch.4. Entity Relationship Modeling
2.11
Ch.4. Entity Relationship Modeling
• Weak Entity
▪ Depends on a strong entity and cannot exist on its own
▪ No unique identifier (only a partial identifier)
▪ E.g., adventureworks.sales.SalesOrderHeaderSalesReason
▪ Using a solid line to present the relationship (non-identifying relationship)
2.12
Ch.4. Entity Relationship Modeling
Weak Entity
Strong Entity
No unique identifier
VIN alone can be
for individual vehicles
a unique identifier
2.13
Ch.4. Entity Relationship Modeling
• Supertype: a generic entity type that has a relationship with one or more subtypes
(e.g., adventureworks.HumanResources.Employee)
• Subtype: a subgrouping of the entities in an entity type that has attributes distinct
from those in other subgroupings (e.g, adventureworks.sales.SalesPerson)
Supertype Entity
Subtype Entities
2.14
Ch.4. Entity Relationship Modeling
Section. 3
Attributes
2.15
Ch.4. Entity Relationship Modeling
Attributes
• Properties or characteristics of an entity or relationship type
(corresponds to columns in a table)
• Classifications of attributes:
• Identifier (e.g., VIN, EmployeeID)
• Required vs. Optional (e.g., LastName vs. CustomerHobby)
• Simple (atomic) vs. Composite (e.g., FirstName vs. MailingAddress)
• Single-Valued vs. Multivalued (e.g., MaritalStatus vs. CustomerInterests)
• Stored vs. Derived (DateOfBirth vs. Age)
CUSTOMER
Attributes customer_id name
CID1 A
CID2 B
CID3 C
CID4 D
CID5 E
2.16
Ch.4. Entity Relationship Modeling
2.17
Ch.4. Entity Relationship Modeling
▪ Understand the nature of attributes to find errors (e.g., max. and min. values)
▪ Define or develop an unique identifier for each row (e.g., customer ID vs. order ID)
▪ Divide multivalued attributes into single valued attributes (e.g., year from date)
2.18
Ch.4. Entity Relationship Modeling
Functional Dependency
• A functional dependency occurs when the value of one (set of) attribute(s)
determines the value of a second (set of) attribute(s):
▪ StudentID - StudentName
▪ StudentID - (DormName, DormRoom, DormFee)
• The attribute on the left of the functional dependency is called the determinant
• Functional dependencies could rely on equations:
2.19
Ch.4. Entity Relationship Modeling
Determines
2.20
Ch.4. Entity Relationship Modeling
Composite Determinants
2.21
Ch.4. Entity Relationship Modeling
2.22
Ch.4. Entity Relationship Modeling
2.23
Ch.4. Entity Relationship Modeling
Section. 4
Keys
2.24
Ch.4. Entity Relationship Modeling
Keys
• Key: one or combination of more than one attribute to identify rows in a relation
• Composite key: the key that consists of two or more attributes
• Candidate key: the key that can determine other attributes in a relation
• Primary key: a candidate key selected as the primary means of identifying rows
in a relation;
2.25
Ch.4. Entity Relationship Modeling
PURCHASING.VENDOR
BusinessEntityID AccountNumber Name CreditRating PreferredVendorStatus
1492 AUSTRALI0001 Australia Bike Retailer 1 1
1494 ALLENSON0001 Allenson Cycles 2 1
1496 ADVANCED0001 Advanced Bicycles 1 1
1498 TRIKES0001 Trikes, Inc. 2 1
PURCHASING.PRODUCTVENDOR
ProductID BusinessEntityID AverageLeadTime StandardPrice LastReceiptCost
1 1492 17 47.87 50.26
2 1494 19 39.92 41.92
4 1496 17 54.31 57.03
317 1498 19 28.17 29.58
2.26
Ch.4. Entity Relationship Modeling
Foreign Key
• The primary key of one relation that is placed in another relation to form a link
between the relations (used for combining multiple tables)
• Either a single key or a composite key
2.27
Ch.4. Entity Relationship Modeling
Surrogate Key
• An artificial attribute added to a relation to serve as primary key
▪ Supplied (or generated) by DBMS (Database Management Systems)
▪ Short, numeric, and never changes—an ideal primary key
▪ Has artificial values that are meaningless to users
▪ Normally hidden in forms and reports because it is hard to understand
▪ E.g., product bar code, Amazon ASIN code, etc.
2.28
Ch.4. Entity Relationship Modeling
Integrity Constraints (1 of 3)
• Set of constraints or rules that limit acceptable values and actions for attributes
• Used to maintain accuracy and integrity of data in the database
• Domain Constraints
▪ A set of possible values that may be assigned to an attribute
▪ Values in a column of a relation must meet the column (i.e., attribute) definitions
▪ Usually consists of domain name, meaning, data type, size, and allowable range
2.29
Ch.4. Entity Relationship Modeling
Integrity Constraints (2 of 3)
• Entity Integrity
Entity integrity is concerned with a primary key;
▪ Every relation has a primary key (otherwise, weak entity)
▪ Data values for the primary key are all valid
▪ Every primary key attribute is NOT null
ID Semester Age
1000 1st 34
1001 2nd 23
ID (primary key) 1002 3rd 29
should not be Null
NULL 4th 30
1004 5th 22
2.30
Ch.4. Entity Relationship Modeling
Integrity Constraints (3 of 3)
• Referential Integrity Constraints
▪ The statement that limits the values of the foreign key to those already existing
as primary key values in the corresponding relation
▪ E.g., CustomerID must have the same constrains in the both relations to identify
customers from one to another relation (e.g., only four numbers or combination
of two letters and four numbers)
2.31
Ch.4. Entity Relationship Modeling
Section. 5
2.32
Ch.4. Entity Relationship Modeling
Relationships
2.33
Ch.4. Entity Relationship Modeling
Relationships: Cardinality
2.34
Ch.4. Entity Relationship Modeling
2.35
Ch.4. Entity Relationship Modeling
One
2.36
Ch.4. Entity Relationship Modeling
2.37
Ch.4. Entity Relationship Modeling
Table to Relation
ORDER CUSTOMER
Order Order Customer Customer Customer Customer
ID Date ID ID Name Address
OD2 20220929 C2 C1 Nick address_1
OD3 20220929 C3 C2 Tom address_2
OD4 20220929 C4 C3 Harry address_3
OD5 20220930 C1 C4 Andrea address_4
OD6 20220930 C2
OD7 20220930 C3
OD8 20220930 C4
Made by
ORDER CUSTOMER
Makes
2.38
Ch.4. Entity Relationship Modeling
Relationships
• One-to-One: each entity in the relationship will have exactly one related entity
• One-to-Many: an entity on one side of the relationship can have many related
entities, but an entity on the other side will have a maximum of one related entity
• Many-to-Many: entities on both sides of the relationship can have many related
entities on the other side
Many-to-Many
One professor must be qualified for one or more than one course,
while one course must be associated with one or more than one professor
2.39
Ch.4. Entity Relationship Modeling
Degree of Relationship
• Unary (degree one): entities of the same entity type related to each other
• Binary (degree two): entities of one type related to entities of another
(most common)
• Ternary (degree three): entities of three different types involved in the
same relationship
2.40
Ch.4. Entity Relationship Modeling
2.41
Ch.4. Entity Relationship Modeling
References
• The major contents of this note are reproduced from the textbook of BCIS 5420;
Topi et al. Modern Database Management. 13 th edition. Pearson's, 2019
• Unless having a specific reference source, the photos and icons used in this
material are from the following sources providing copyright free images:
imagesource.com, iconfinder.com, and pexels.com
2.42