Mapping from Data Model ERD to Relational Model

  • Slides: 34
Download presentation
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

Transformation n Transform the conceptual database design (ERD) into a logical database design that

Transformation n Transform the conceptual database design (ERD) into a logical database design that can be implemented on a chosen DBMS later (our choice: RDS) n n Input: conceptual model (ERD) Output: relational model (schema), normalized relations

Why do I need to know this? n CASE tools can perform many of

Why do I need to know this? n CASE tools can perform many of the transformation steps automatically, but. . n Often CASE tools cannot model complexity of data and relationship n n Example: ternary relationship, supertype and subtype relationship You must be able to perform a quality check on CASE tool results

Transformation Procedure n n An entity turns into a table. Each attribute turns into

Transformation Procedure n n 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. n Restaurant database: next slide

Access Data Model 5

Access Data Model 5

Composite and Multi-valued Attributes n An attribute is considered composite if it comprises two

Composite and Multi-valued Attributes n An attribute is considered composite if it comprises two or more other attributes. n n Divided into atomic and separate attribute There should no such thing as a multi-valued attribute (phone #) in a relational database. n n Against “Set Theory” “Multi-valued Attribute” must be turned into a new entity of its own…. .

Mapping an entity into a relation n n An Entity name: Employee Attributes: n

Mapping an entity into a relation n n An Entity name: Employee Attributes: n n Emp_ID, Emp_Lname, Emp_Fname, Salary Identifier: Emp_ID Employee Emp_Id PK Emp_Lname Emp_Fname Salary

Mapping an entity into a relation Movies Title Year Length Film Type Movies title

Mapping an entity into a relation Movies Title Year Length Film Type Movies title year Star Wars Mighty Ducks Wayne’s World length film. Type 1977 124 color 1991 104 color 1992 95 color

Mapping binary relationships n One-to-one: if there is no indication of optionality, then it

Mapping binary relationships n One-to-one: if there is no indication of optionality, then it needs to be decided by developers. n n one-to-one mandatory relationship Restaurant DB: Billing. Address 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

Mapping a 1: 1 relationship with optionality on the one side n Nurse: n

Mapping a 1: 1 relationship with optionality on the one side n Nurse: n n Nurse_ID, Name, Date_of_Birth Care Center n Center_Name, Location, Date_Assigned

Mapping a 1: 1 relationship OK to use Nurse_ID Access: - Name must be

Mapping a 1: 1 relationship OK to use Nurse_ID Access: - Name must be matched FK: Nurse_ID

Mapping a 1: M relationship n Customer: n n Customer_ID, Customer_Name, Customer_Address Order: n

Mapping a 1: M relationship n Customer: n n Customer_ID, Customer_Name, Customer_Address Order: n Order_ID, Order_Date

Mapping a 1: M relationship FK

Mapping a 1: M relationship FK

Mapping M: N relationship Each student takes many classes, and a class must be

Mapping M: N relationship Each student takes many classes, and a class must be taken by many students. CLASS IS_TAKEN_BY STUDENT TAKE

Transformation of M: N n n CLASS The relational operations become very complex and

Transformation of M: N n n CLASS 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). Class_ Student STUDENT

Example M: N Relationship Table to represent Entity 3 to 3 30 to 30

Example M: N Relationship Table to represent Entity 3 to 3 30 to 30 300 to 3000 30, 000 to 30, 000 300, 000 to 300, 000

Converting M: N Relationship to Two 1: M Relationships Bridge Entity

Converting M: N Relationship to Two 1: M Relationships Bridge Entity

Mapping an M: N relationship Student STU_NUM STU_LNAME Enroll CLASS CODE (added later!) STU_NUM

Mapping an M: N relationship Student STU_NUM STU_LNAME Enroll CLASS CODE (added later!) STU_NUM ENROLL_GRADE Class CLASS CODE CRS_CODE CLASS_ROOM PROF_NUM CLASS_SECTION CLASS_TIME

Mapping a bridge entity with its own name and identifier Customer_ID Name Other Attributes

Mapping a bridge entity with its own name and identifier Customer_ID Name Other Attributes Shipment_NO Customer_ID Vendor_ID Date Amount Vendor_ID Address Other Attributes

Mapping a bridge entity with its own identifier (con’t)

Mapping a bridge entity with its own identifier (con’t)

Mapping composite and Multi-valued attributes to relation n n Composite attribute: use only their

Mapping composite and Multi-valued attributes to relation n n Composite attribute: use only their simple, component attributes – divide into atomic and separate attribute. Multi-valued attribute: turned it into a new entity of its own…. .

Mapping composite attributes to relation Customer_ID Customer_Name Customer_Address Composite attribute

Mapping composite attributes to relation Customer_ID Customer_Name Customer_Address Composite attribute

Mapping a multi-valued attribute Employee SSN Name Phone # Phone Employee SSN Name SSN

Mapping a multi-valued attribute Employee SSN Name Phone # Phone Employee SSN Name SSN Phone# E 101 Johnson E 101 312 … E 102 Smith E 102 708 … E 103 Conley E 102 312 … E 104 Roberts E 104 603 …

Mapping a weak entity n n Becomes a separate relation with a FK taken

Mapping a weak entity n n Becomes a separate relation with a FK taken from the regular entity Primary key composed of: n n Partial identifier of weak entity Primary key of identifying relation

Mapping a weak entity In general, identifier of the regular entity is not included

Mapping a weak entity In general, identifier of the regular entity is not included during the modeling

Mapping a weak entity Employee Emp_ID Dependent Dep_SS_No Emp_name FK Emp_ID NOTE: The FK

Mapping a weak entity Employee Emp_ID Dependent Dep_SS_No Emp_name FK Emp_ID NOTE: The FK of DEPENDENT should NOT allow null value if DEPENDENT is a weak entity Lname Fname DOB Gender

Mapping 1: M recursive (or unary) relationship

Mapping 1: M recursive (or unary) relationship

Mapping 1: M recursive (or unary) relationship Employee FK Emp_ID Emp_Name Emp_Address Manager_ID •

Mapping 1: M recursive (or unary) relationship Employee FK Emp_ID Emp_Name Emp_Address Manager_ID • Manager_ID references Emp_ID

Mapping Supertype/subtype relationship n n Create a separate relation for the supertype and each

Mapping Supertype/subtype relationship n n Create a separate relation for the supertype and each of the subtypes Assign common attributes to supertype Assign PK and unique attributes to each subtype Assign an attribute of the supertype to act as subtype discriminator

Mapping Supertype/subtype relationship

Mapping Supertype/subtype relationship

Mapping Supertype/subtype relationship

Mapping Supertype/subtype relationship

Mapping Ternary Relationship

Mapping Ternary Relationship

Mapping Ternary Relationship

Mapping Ternary Relationship