Mapping From Data Model (ERD) To Relational Model: Yong Choi School of Business Csub
Mapping From Data Model (ERD) To Relational Model: Yong Choi School of Business Csub
Mapping From Data Model (ERD) To Relational Model: Yong Choi School of Business Csub
Yong Choi
School of Business
CSUB
Transformation
Transform the conceptual database design
(ERD) into a logical database design that can
be implemented on a chosen DBMS later (our
choice: RDS)
Input: conceptual model (ERD)
Output: relational model (schema), normalized
relations
Why do I need to know this?
CASE tools can perform many of the
transformation steps automatically, but..
Often CASE tools cannot model complexity of data
and relationship
Example: ternary relationship, supertype and subtype
relationship
You must be able to perform a quality check on CASE
tool results
Transformation Procedure
An entity turns into a table.
Each attribute turns into a column in the
table.
The (unique) identifier of the entity turns into
a PK of the table.
In general, the ERD (data model) does not
include FK information.
Restaurant database: next slide
Access Data Model
5
Review of Relational Model (schema)
* The Relational model does not like any type of
redundancies.
Every table must have a unique name.
Attributes in tables must have unique names.
Every attribute value must be atomic.
The order of the columns & rows are irrelevant.
Primary Key
is a key in a relational database system that is
unique for each record (or row) and a table as
well.
Unique identifier of each record (and table).
Example:
SS#, driver license number, vehicle identification
number (VIN).
Rule for Primary Key
No “null” value can be allowed.
Null value is not equal to zero.
OK to have “null” value for a non-PK.
Rule for Primary Key con’t
Employee
Emp_Id Emp_Lname Emp_Fname Salary
PK
Mapping an entity into a relation
Movies
Movies
title year length filmType
Title
Star Wars 1977 124 color
Year
Mighty
Length Ducks
1991 104 color
Film Type Wayne’s
World
1992 95 color
Mapping binary relationships
One-to-one: if there is no indication of optionality,
then it needs to be decided by developers.
one-to-one mandatory relationship
Restaurant DB: BillingAddress and Customer
One-to-many: PK on the one side becomes FK on
the many side
Many-to-many - create a new relation (bridge entity)
with the PKs of the two entities as its composite PK
Mapping a 1:1 relationship
Mapping a 1:1 relationship with
optionality on the one side
Nurse:
Nurse_ID, Name, Date_of_Birth
Care Center
Center_Name, Location, Date_Assigned
OK to use Nurse_ID
Access:
- Name must be matched
FK: Nurse_ID
Mapping a 1:M relationship
Customer:
Customer_ID, Customer_Name, Customer_Address
Order:
Order_ID, Order_Date
Customer Order
Mapping a 1:M relationship
FK
Mapping M:N relationship
IS_TAKEN_BY
CLASS STUDENT
TAKE
Transformation of M:N
The relational operations become very complex and
are likely to cause system efficiency errors and output
errors.
Break the M:N down into 1:N and N:1 relationships
using bridge entity (weak entity).
3 to 3
30 to 30
300 to 300
3000 to 3000
30,000 to 30,000
300, 000 to 300, 000
Converting M:N Relationship to Two 1:M Relationships
Bridge Entity
Mapping an M:N relationship
Student
STU_NUM STU_LNAME
Class
CLASS CODE CRS_CODE CLASS_SECTION CLASS_TIME
CLASS_ROOM PROF_NUM
Mapping a bridge entity
with its own name and identifier
Customer Shipment Vendor
Dependen t
Employee Dep_SS_No
Emp_ID Lname
Emp_Nam e Fname
DOB
Gender
In general, identifier of the regular entity
is not included during the modeling
Mapping a weak entity
Employee NOTE: The FK of
DEPENDENT should NOT
Emp_ID Emp_name allow null value if
DEPENDENT is a weak
entity
Dependent FK
Dep_SS_No Emp_ID Lname Fname DOB Gender
Mapping 1:M recursive (or unary)
relationship
Employee
Emp_ID
Emp_Name
Emp_Address
Mapping 1:M recursive (or unary)
relationship
Employee FK
Emp_ID Emp_Name Emp_Address Manager_ID