Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

An ER Diagram Is A Pictorial Representation of The Information That Can Be Captured by A Database. Such A "Picture" Serves Two Purposes

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

• An ER diagram is a pictorial representation of the

information that can be captured by a database. Such


a “picture” serves two purposes:
– It allows database professionals to describe an overall design concisely
yet accurately.
– (Most of) it can be easily transformed into the relational schema.
• The ER diagram represents the conceptual level of database
design meanwhile the relational schema (or database table) is
the logical level for the database design.

Thursday, July 01, 2021 CSE, KLEF 1


Converting ER diagram to Tables
• ER-to-Relational Mapping Algorithm

Step 1: Mapping of Regular Entity Types


Step 2: Mapping of Weak Entity Types
Step 3: Mapping of Binary 1:1 Relation Types
Step 4: Mapping of Binary 1:N Relationship Types.
Step 5: Mapping of Binary M:N Relationship Types.
Step 6: Mapping of Multivalued attributes.
Step 7: Mapping of N-ary Relationship Types.

• Mapping EER Model Constructs to Relations

Step 8: Options for Mapping Specialization or Generalization.


Step 9: Mapping of Union Types (Categories).

Thursday, July 01, 2021 CSE, KLEF 2


Converting ER diagram to Tables
• Step1: Mapping of Regular Entity Types
• Entities and Simple Attributes
– An entity type within ER diagram is turned into a table.
– Each attribute turns into a column (attribute) in the table. The key
attribute of the entity is the primary key of the table which is usually
underlined.
USN DOB
Name

Student
Student Table
USN Name DOB
Primary
1BM14CS001 Aditya 1-1-1997
Key
1BM14CS002 Bharath 31-12-1996

Thursday, July 01, 2021 CSE, KLEF 3


Converting ER diagramPartial
to
Key
Tables
Name
• Step 2: Mapping of Weak Entity Types -----
F-ID F-Name

Faculty Dependents_of
Dependent

Owner
Identifying Weak
Entity
Relationship Entity

Thursday, July 01, 2021 CSE, KLEF 4


Converting ER diagramPartial
to Tables
Name
Key -----
• Weak Entity
F-ID F-Name

Faculty Dependents_of
Dependent

Owner
Identifying Weak
Entity
Relationship Entity

Faculty Table Dependent Table


F-ID F-Name F-ID Dependent
Name
10 Dr. Guruprasad 10 Ram
20 Dr. Gowrishankar 10 Ravi
20 Ram

Thursday, July 01, 2021 CSE, KLEF 5


Converting ER diagram to Tables
• Step 3: Mapping of Binary 1:1 Relation Types
• Relationship: One-to-One

D-ID
F-ID 1
1

F-Name
D-Name

Thursday, July 01, 2021 CSE, KLEF 6


Converting ER diagram to Tables
• Relationship: One-to-One
D-ID
F-ID 1
1

F-Name
D-Name

Approach 1: Foreign Key


Faculty Table Department Table
F-ID F-Name
D-ID D-Name Heading
1 Dr. H S Guruprasad F-ID
2 Dr. Umadevi V 10 CSE 1
3 Dr. Gowrishankar 20 ISE 3

Thursday, July 01, 2021 CSE, KLEF 7


Converting ER diagram to Tables
• Relationship: One-to-One
D-ID
F-ID 1
1

F-Name
D-Name

Approach 1: Foreign Key


Department Table
Primary Primary Foreign
Key Faculty Table Key Key
F-ID F-Name
D-ID D-Name Heading
1 Dr. H S Guruprasad F-ID
2 Dr. Umadevi V 10 CSE 1
3 Dr. Gowrishankar 20 ISE 3

Thursday, July 01, 2021 CSE, KLEF 8


Converting ER diagram to Tables
• Relationship: One-to-One
D-ID
F-ID 1
1

F-Name
D-Name
Approach 2: Merged Relation approach
Merging two entity types and relationship into one single relation.
This may be appropriate when both participations are total

Faculty –Department Table


F- F-Name D-ID D-Name HOD
ID
1 Dr. H S Guruprasad 10 CSE Yes
2 Dr. Umadevi V 10 CSE No
3 Dr. Gowrishankar 20 ISE Yes

Thursday, July 01, 2021 CSE, KLEF 9


Converting ER diagram to Tables
• Relationship: One-to-One
D-ID
F-ID
1 1

F-Name
D-Name
Approach 3: Cross-reference or relationship relation approach

Faculty Table Department Table HOD Table


F-ID F-Name D-ID D-Name D-ID F-ID
1 Dr. H S Guruprasad 10 1
10 CSE
2 Dr. Umadevi V 20 3
20 ISE
3 Dr. Gowrishankar
Lookup Table

Thursday, July 01, 2021 CSE, KLEF 10


Converting ER diagram to Tables
• Step 4: Mapping of Binary 1:N Relationship Types
• Relationship: One-to-Many

USN
D-ID M
Departme 1 Student
Has
nt
D-Name
S-Name

Thursday, July 01, 2021 CSE, KLEF 11


Converting ER diagram to Tables
• Relationship: One-to-Many
USN
D-ID M
Departme 1 Student
Has
nt
D-Name
S-Name
Approach 1 Student Table
USN S-Name D-ID
Department Table
D-ID D-Name 1BM14CS001 Akash 10
10 CSE 1BM14CS002 Bharath 10
20 ISE 1BM14CS003 Ragu 10
1BM14CS004 Mohan 20
1BM14CS005 Nikil 20

Thursday, July 01, 2021 CSE, KLEF 12


Converting ER diagram to Tables
• Relationship: One-to-Many
USN
D-ID M
Departme 1 Student
Has
nt
D-Name
S-Name
Approach 2 Student Table Department
Department Table
USN S-Name Student Table
USN D-ID
D-ID D-Name 1BM14CS001 Akash
1BM14CS002 Bharath 1BM14CS001 10
10 CSE
1BM14CS003 Ragu 1BM14CS002 10
20 ISE
1BM14CS004 Mohan 1BM14CS003 10
1BM14CS005 Nikil 1BM14CS004 20
1BM14CS005 20

Thursday, July 01, 2021 CSE, KLEF 13


Converting ER diagram to Tables
• Step 5: Mapping of Binary M:N Relationship Types
• Relationship: Many-to-Many

USN C-ID
Enrolls_for
Student Course
S-Name C-Name
Thursday, July 01, 2021 CSE, KLEF 14
Converting ER diagram to Tables
• Relationship: Many-to-Many
USN C-ID
Enrolls_for
Student Course
S-Name C-Name

Student Table Course Table Student


Course Table
USN S-Name C-ID C-Name
USN C-ID
1BM14CS001 Avinash 10 DBMS
1BM14CS001 10
1BM14CS002 Balaji 20 Java
1BM14CS001 20
1BM14CS003 Chandan
1BM14CS002 20
1BM14CS003 10

Thursday, July 01, 2021 CSE, KLEF 15


Converting ER diagram to Tables
• Relationship: Many-to-Many
USN C-ID
Enrolls_for
Student Course
S-Name C-Name

Student Table Course Table Student


Course Table
USN S-Name C-ID C-Name
USN C-ID
1BM14CS001 Avinash 10 DBMS
1BM14CS001 10
1BM14CS002 Balaji 20 Java
1BM14CS001 20
1BM14CS003 Chandan
1BM14CS002 20
1BM14CS003 10

Thursday, July 01, 2021 CSE, KLEF 16


Converting ER diagram to Tables
• Step 6: Mapping of Multivalued attributes.
USN DOB
Name

Mobile
Student

Thursday, July 01, 2021 CSE, KLEF 17


Converting ER diagram to Tables
• Mapping of Multivalued attributes.
USN DOB
Name

Mobile
Student
Which of the following representation of the table for Multivalued
Attribute is best ?
USN Name DOB Mobile 1 Mobile 2
1BM14CS001 Aditya 1-1-1997 8766655433

1BM14CS002 Bharath 31-12-1996 9762255433 7066722433

Mobile Table
Student Table
USN Mobile
USN Name DOB
1BM14CS001 8766655433
1BM14CS001 Aditya 1-1-1997
1BM14CS002 9762255433
1BM14CS002 Bharath 31-12-1996
1BM14CS002 7066722433

Thursday, July 01, 2021 CSE, KLEF 18


Converting ER diagram to Tables
• Multi-Valued Attributes USN DOB
Name
Primary
Key Mobile
Student

Student Table Mobile Table


USN Mobile
USN Name DOB Foreign
1BM14CS001 8766655433
1BM14CS001 Aditya 1-1-1997 Key
1BM14CS002 9762255433
1BM14CS002 Bharath 31-12-1996
1BM14CS002 7066722433

If you have a multi-valued attribute, take the attribute and turn it into a
new entity or table of its own. Then make a 1:N relationship between
the new entity and the existing one. In simple words,
1. Create a table for the attribute.
2. Add the primary (id) column of the parent entity as a foreign key
within the new table
Thursday, July 01, 2021 CSE, KLEF 19
Converting ER diagram to Tables
Street Area
Name Name
• Composite Attribute
Address Place
USN DOB
Name

Student Mobile

Thursday, July 01, 2021 CSE, KLEF 20


Converting ER diagram to Tables
Street Area
Name Name

• Composite Attribute DOB Address Place


USN Name

Student Mobile

Student Table
USN Name DOB Street Area Place
1BM14CS001 Aditya 1-1-1997 RK Road Nagar Mandya

1BM14CS002 Bharath 31-7-1996 S V Road Layout Kolar

USN Mobile
Mobile Table 1BM14CS001 8766655433

1BM14CS002 9762255433

1BM14CS002 7066722433
Thursday, July 01, 2021 CSE, KLEF 21
Converting ER diagram to Tables
Street Area
Name Name

• Derived Attribute DOB Address Place


USN Name

Age Student Mobile

Student Table
USN Name DOB Street Area Place
1BM14CS001 Aditya 1-1-1997 RK Road Nagar Mandya

1BM14CS002 Bharath 31-7-1996 S V Road Layout Kolar

USN Mobile
1BM14CS001 8766655433

Mobile Table 1BM14CS002 9762255433

1BM14CS002 7066722433

Thursday, July 01, 2021 CSE, KLEF 22


Converting ER diagram to Tables
Step 7: Mapping of N-ary Relationship Types
– Create a new relation S to represent R.
– Include as foreign key attributes in the S the primary keys of the
relations that represent the participating entity types.
– Also include any simple attributes of the nary relationship types as
attributes of S.
– The primary key for S is usually a combination of all the foreign keys
that reference the relations representing the participating entity
types.

Thursday, July 01, 2021 CSE, KLEF 23

You might also like