ER to Relational Mapping
OBJECTIVES
 To understand the concept of mapping.
 To bring out solution of ER model to relational mapping model
 To known about the mapping process in this ppt.
 To understand about the weak entity set relationship mapping.
ER Model to Relational Model
data mapping is the process of mapping data fields from a source file
to their related target fields. Its two types:
Conceptual/Internal Mapping. External/Conceptual Mapping. ER
Model, when conceptualized into diagrams, gives a good overview of
entity-relationship, which is easier to understand. ER diagrams can be
mapped to relational schema, that is, it is possible to create relational
schema using ER diagram. We cannot import all the ER constraints into
relational model, but an approximate schema can be generated.
There are several processes and algorithms available to convert ER
Diagrams into Relational Schema. Some of them are automated and
some of them are manual. We may focus here on the mapping
diagram contents to relational basics. ER diagrams mainly comprise of
−:
 Entity and its attributes
 Relationship, which is association among entities.
Mapping Entity
 An entity is a real-world object with some attributes. So we here select mapping entity is
Employee with its attributes eno , ename and salary. So what is mapping process is used to
entity related to each attributes. Lets see:
Mapping Process (Algorithm)
• Create table for each entity.
• Entity's attributes should become fields of tables with their respective data types.
• Declare primary key.
Mapping Relationship
A relationship is an association among entities. Consider the works-in relationship shown in the
following figure.
Mapping Process for Relationship
•Create table for a relationship.
•Add the primary keys of all participating Entities as fields of table with their respective data types.
•If relationship has any attribute, add each attribute as field of table.
•Declare a primary key composing all the primary keys of participating entities.
•Declare foreign key constraints if use.
Mapping Weak Entity Sets
An entity set attributes that does not have a primary key within them, is termed as a weak entity set. As
an example, consider the entity set Payment, which has the three attributes: payment - number,
payment - date and payment - amount, illustrated with the following E-R diagram:
Mapping Process
•Create a new relation.
•Include the simple attributes.
•Add the owners primary key attributes as foreign key attributes.
•Declare into a primary key the partial keys of the weak entity type combined with those imported from the owner
Mapping Strong Entity Sets
An entity set attributes that does not have a primary key within them, is termed as a weak entity set. As
an example, consider the entity set Payment, which has the three attributes: payment - number,
payment - date and payment - amount, illustrated with the following E-R diagram:
Mapping Process
•Create a new relation.
•Include the simple attributes.
•Include the simple components of the composite attributes.
•Identify the primary keys. If a chosen key composite that the set of simple attributes that form it will together form
the primary key.
•Don’t include: non-simple components of composite attributes, foreign keys, derived attributes.
Mapping of Binary 1:1 relationship mapping
•Foreign key approach
•Merged relation option
•Cross-references or relationship relation
Foreign Key Approach
Identify the relations A and B that correspond to the entity types participating in R.
Include as foreign keys, in the relation of one entity type, the primary keys of the other entity type
The entity having total participation must have the foreign key of the other entity.
Include also the simple attributes of the relationship type
DEPARTMENT has total participation. Therefore, DEPARTMENT contains the foreign key, the primary key of
EMPLOYEE.
Mapping of Binary 1:1 relationship mapping
Merged Relation Option
1. Merge the two entity types and the relationship into a single relation.
2. This may be appropriate when both participation are total.
Mapping of Binary 1:1 relationship mapping
Cross-reference Option:
Create a third relation R for the purpose of cross-referencing the primary keys of the two relations A and B
representing the entity types.
Mapping of Binary 1:N relationship mapping
Add as foreign keys, to the relation of the entity type at the N side, the primary keys of the entity type
at the 1 side (don’t duplicate records!)
Include also the simple attributes of the relationship type.
Mapping of Binary M:N relationship mapping
Create a new relation.
add as primary key and foreign key participating entity types to the relationship type(their
combination will form the primary key)
Include the simple attributes of the relationship type.
Mapping Hierarchical Entities
ER specialization or generalization comes in the form of hierarchical entity sets. To classify the
entities in an entity set into subclass entity, is known as class hierarchies. Example, we might
want to classify Employees entity set into subclass entities Hourly-Emps entity set and Contract-
Emps entity set to distinguish the basis on which they are paid. Then the class hierarchy is
illustrated as follows:
This class hierarchy illustrates the inheritance concept. Where, the subclass attributes ISA
(read as is a) super class attributes; indicating the “is a” relationship (inheritance
concept).Therefore, the attributes defined for a Hourly- Emps entity set are the attributes of
Hourly-Emps plus attributes of Employees (because subclass can have super class properties).
Likewise the attributes defined for a Contract-Emps entity set are the attributes of Contract-
Emps plus attributes of Employees.
Mapping Process
 Create tables for all higher-level entities.
 Create tables for lower-level entities.
 Add primary keys of higher-level entities in the table of lower-level entities.
 In lower-level tables, add all other attributes of lower-level entities.
 Declare primary key of higher-level table and the primary key for lower-level table.
 Declare foreign key constraints.
Mapping Hierarchical Entities
ER specialization or generalization comes in the form of hierarchical entity sets. To classify the
entities in an entity set into subclass entity, is known as class hierarchies. Example, we might
want to classify Employees entity set into subclass entities Hourly-Emps entity set and Contract-
Emps entity set to distinguish the basis on which they are paid. Then the class hierarchy is
illustrated as follows:
Aggregation versus Ternary Relationships Mapping
The choice between using aggregation or a ternary relationship is mainly determined by the existence
of a relationship that relates a relationship set to an entity set (or second relationship set).
Example: Consider the constraint that each sponsorship (of a project by a department) be monitored
by at most one employee. We can express this constraint in terms of the Sponsors relationship set. On
the other hand, we can easily express the constraint by drawing an arrow. from the aggregated
relationship Sponsors to the relationship Monitors. Thus, the presence of such a constraint serves as
another reason for using aggregation rather than a ternary relationship set.
Mapping Process
 Create tables for all higher-level entities.
 Create tables for lower-level entities.
 Add primary keys of higher-level entities in the table of lower-level entities.
 In lower-level tables, add all other attributes of lower-level entities.
 Check relationship before mapping in aggregation or ternary relationship.
Some point remember when you generate or create relational schema
using ER Diagram
 Entity gets converted into Table, with all the attributes becoming fields(columns) in the
table.
 Relationship between entities is also converted into table with primary keys of the related
entities also stored in it as foreign keys.
 Primary Keys should be properly set.
 For any relationship of Weak Entity, if primary key of any other entity is included in a table,
foreign key constraint must be defined.
Union
U
Subclass related to a collection of superclasses
Each instance of subclass belongs to one, not all of the superclasses
Superclasses form a union
Category can be total or partial
Subclass is called a category or UNION TYPE
Live Example to create ER Model to
Relational Model Mapping
My first motto to converting all strong entity in to table form. After that ER Model to Converting
to Relational Model.
Step 1-: Firstly all strong entity sets in to relation:----:
Step 2: In this step firstly mapping of weak entity types:
1. Create a separate relation.
2. After include all simple attributes.
3. Add primary key of the owner entity set into weak entity set.
4. Weak entity is associated the strong entity.
5. Associate foreign key in a particular.
Step 3: Now perform Mapping 1:1:
There are three methods used to perform 1:1 mapping:
1. Foreign key approach:
a) Identify entity set with total participation.
b) Add primary key of R into S as foreign key.
2. Merge Relation:
a) If both entity sets are having total participation then they have can
be merged into a single relation.
3. Cross Reference approach
1. Create a third relation comprising primary key of both entity sets.
Step 4: Mapping 1:N Relationship:
Let R and S be the entity sets (with 1:N) where S is having total participating in Relationship.
1. Add primary key of R in S as foreign key from 1 side to N side.
Step 5: Mapping M:N Relationship:
create a third relation containing the primary keys of both the entity sets and descriptive
attributes (Hours) (if any)
1. Add primary key of R in S as foreign key from 1 side to N side.
2. We create a separate table along with the descriptive attributes. (ssn and pno both are
composite keys)
Step 6: Mapping multivalued attributes:
1. For each multivalued attributes , create a separate relation.
2. Add primary key of entity set in a new relation as a foreign key.
3. Foreign key attributes & multivalued attributes become composite key. So that Dno works
as a composite key in your table.
Step 7: N-ary Relationship:
1. For each N-ary relationship create a separate relation.
2. New relation will contain the primary keys of all entity sets forming N-ary relationship.
Thank You

ER to Relational Mapping

  • 1.
  • 2.
    OBJECTIVES  To understandthe concept of mapping.  To bring out solution of ER model to relational mapping model  To known about the mapping process in this ppt.  To understand about the weak entity set relationship mapping.
  • 3.
    ER Model toRelational Model data mapping is the process of mapping data fields from a source file to their related target fields. Its two types: Conceptual/Internal Mapping. External/Conceptual Mapping. ER Model, when conceptualized into diagrams, gives a good overview of entity-relationship, which is easier to understand. ER diagrams can be mapped to relational schema, that is, it is possible to create relational schema using ER diagram. We cannot import all the ER constraints into relational model, but an approximate schema can be generated. There are several processes and algorithms available to convert ER Diagrams into Relational Schema. Some of them are automated and some of them are manual. We may focus here on the mapping diagram contents to relational basics. ER diagrams mainly comprise of −:  Entity and its attributes  Relationship, which is association among entities.
  • 4.
    Mapping Entity  Anentity is a real-world object with some attributes. So we here select mapping entity is Employee with its attributes eno , ename and salary. So what is mapping process is used to entity related to each attributes. Lets see: Mapping Process (Algorithm) • Create table for each entity. • Entity's attributes should become fields of tables with their respective data types. • Declare primary key.
  • 5.
    Mapping Relationship A relationshipis an association among entities. Consider the works-in relationship shown in the following figure. Mapping Process for Relationship •Create table for a relationship. •Add the primary keys of all participating Entities as fields of table with their respective data types. •If relationship has any attribute, add each attribute as field of table. •Declare a primary key composing all the primary keys of participating entities. •Declare foreign key constraints if use.
  • 6.
    Mapping Weak EntitySets An entity set attributes that does not have a primary key within them, is termed as a weak entity set. As an example, consider the entity set Payment, which has the three attributes: payment - number, payment - date and payment - amount, illustrated with the following E-R diagram: Mapping Process •Create a new relation. •Include the simple attributes. •Add the owners primary key attributes as foreign key attributes. •Declare into a primary key the partial keys of the weak entity type combined with those imported from the owner
  • 7.
    Mapping Strong EntitySets An entity set attributes that does not have a primary key within them, is termed as a weak entity set. As an example, consider the entity set Payment, which has the three attributes: payment - number, payment - date and payment - amount, illustrated with the following E-R diagram: Mapping Process •Create a new relation. •Include the simple attributes. •Include the simple components of the composite attributes. •Identify the primary keys. If a chosen key composite that the set of simple attributes that form it will together form the primary key. •Don’t include: non-simple components of composite attributes, foreign keys, derived attributes.
  • 8.
    Mapping of Binary1:1 relationship mapping •Foreign key approach •Merged relation option •Cross-references or relationship relation Foreign Key Approach Identify the relations A and B that correspond to the entity types participating in R. Include as foreign keys, in the relation of one entity type, the primary keys of the other entity type The entity having total participation must have the foreign key of the other entity. Include also the simple attributes of the relationship type DEPARTMENT has total participation. Therefore, DEPARTMENT contains the foreign key, the primary key of EMPLOYEE.
  • 9.
    Mapping of Binary1:1 relationship mapping Merged Relation Option 1. Merge the two entity types and the relationship into a single relation. 2. This may be appropriate when both participation are total.
  • 10.
    Mapping of Binary1:1 relationship mapping Cross-reference Option: Create a third relation R for the purpose of cross-referencing the primary keys of the two relations A and B representing the entity types.
  • 11.
    Mapping of Binary1:N relationship mapping Add as foreign keys, to the relation of the entity type at the N side, the primary keys of the entity type at the 1 side (don’t duplicate records!) Include also the simple attributes of the relationship type.
  • 12.
    Mapping of BinaryM:N relationship mapping Create a new relation. add as primary key and foreign key participating entity types to the relationship type(their combination will form the primary key) Include the simple attributes of the relationship type.
  • 13.
    Mapping Hierarchical Entities ERspecialization or generalization comes in the form of hierarchical entity sets. To classify the entities in an entity set into subclass entity, is known as class hierarchies. Example, we might want to classify Employees entity set into subclass entities Hourly-Emps entity set and Contract- Emps entity set to distinguish the basis on which they are paid. Then the class hierarchy is illustrated as follows:
  • 14.
    This class hierarchyillustrates the inheritance concept. Where, the subclass attributes ISA (read as is a) super class attributes; indicating the “is a” relationship (inheritance concept).Therefore, the attributes defined for a Hourly- Emps entity set are the attributes of Hourly-Emps plus attributes of Employees (because subclass can have super class properties). Likewise the attributes defined for a Contract-Emps entity set are the attributes of Contract- Emps plus attributes of Employees. Mapping Process  Create tables for all higher-level entities.  Create tables for lower-level entities.  Add primary keys of higher-level entities in the table of lower-level entities.  In lower-level tables, add all other attributes of lower-level entities.  Declare primary key of higher-level table and the primary key for lower-level table.  Declare foreign key constraints.
  • 15.
    Mapping Hierarchical Entities ERspecialization or generalization comes in the form of hierarchical entity sets. To classify the entities in an entity set into subclass entity, is known as class hierarchies. Example, we might want to classify Employees entity set into subclass entities Hourly-Emps entity set and Contract- Emps entity set to distinguish the basis on which they are paid. Then the class hierarchy is illustrated as follows:
  • 16.
    Aggregation versus TernaryRelationships Mapping The choice between using aggregation or a ternary relationship is mainly determined by the existence of a relationship that relates a relationship set to an entity set (or second relationship set). Example: Consider the constraint that each sponsorship (of a project by a department) be monitored by at most one employee. We can express this constraint in terms of the Sponsors relationship set. On the other hand, we can easily express the constraint by drawing an arrow. from the aggregated relationship Sponsors to the relationship Monitors. Thus, the presence of such a constraint serves as another reason for using aggregation rather than a ternary relationship set.
  • 17.
    Mapping Process  Createtables for all higher-level entities.  Create tables for lower-level entities.  Add primary keys of higher-level entities in the table of lower-level entities.  In lower-level tables, add all other attributes of lower-level entities.  Check relationship before mapping in aggregation or ternary relationship.
  • 18.
    Some point rememberwhen you generate or create relational schema using ER Diagram  Entity gets converted into Table, with all the attributes becoming fields(columns) in the table.  Relationship between entities is also converted into table with primary keys of the related entities also stored in it as foreign keys.  Primary Keys should be properly set.  For any relationship of Weak Entity, if primary key of any other entity is included in a table, foreign key constraint must be defined.
  • 19.
    Union U Subclass related toa collection of superclasses Each instance of subclass belongs to one, not all of the superclasses Superclasses form a union Category can be total or partial Subclass is called a category or UNION TYPE
  • 20.
    Live Example tocreate ER Model to Relational Model Mapping
  • 22.
    My first mottoto converting all strong entity in to table form. After that ER Model to Converting to Relational Model. Step 1-: Firstly all strong entity sets in to relation:----:
  • 23.
    Step 2: Inthis step firstly mapping of weak entity types: 1. Create a separate relation. 2. After include all simple attributes. 3. Add primary key of the owner entity set into weak entity set. 4. Weak entity is associated the strong entity. 5. Associate foreign key in a particular.
  • 25.
    Step 3: Nowperform Mapping 1:1: There are three methods used to perform 1:1 mapping: 1. Foreign key approach: a) Identify entity set with total participation. b) Add primary key of R into S as foreign key. 2. Merge Relation: a) If both entity sets are having total participation then they have can be merged into a single relation. 3. Cross Reference approach 1. Create a third relation comprising primary key of both entity sets.
  • 27.
    Step 4: Mapping1:N Relationship: Let R and S be the entity sets (with 1:N) where S is having total participating in Relationship. 1. Add primary key of R in S as foreign key from 1 side to N side.
  • 29.
    Step 5: MappingM:N Relationship: create a third relation containing the primary keys of both the entity sets and descriptive attributes (Hours) (if any) 1. Add primary key of R in S as foreign key from 1 side to N side. 2. We create a separate table along with the descriptive attributes. (ssn and pno both are composite keys)
  • 31.
    Step 6: Mappingmultivalued attributes: 1. For each multivalued attributes , create a separate relation. 2. Add primary key of entity set in a new relation as a foreign key. 3. Foreign key attributes & multivalued attributes become composite key. So that Dno works as a composite key in your table. Step 7: N-ary Relationship: 1. For each N-ary relationship create a separate relation. 2. New relation will contain the primary keys of all entity sets forming N-ary relationship.
  • 35.