0% found this document useful (0 votes)
5 views39 pages

ER To Relational Model

The document outlines the process of converting an Entity-Relationship (ER) diagram into a relational schema, detailing the treatment of strong entities, composite attributes, multivalued attributes, and relationships. It explains how to create relational tables from these components, including defining primary and foreign keys, and discusses various cardinality ratios in binary relationships. Additionally, it provides examples and tasks for students to practice converting ER diagrams to relational schemas.

Uploaded by

Praket Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views39 pages

ER To Relational Model

The document outlines the process of converting an Entity-Relationship (ER) diagram into a relational schema, detailing the treatment of strong entities, composite attributes, multivalued attributes, and relationships. It explains how to create relational tables from these components, including defining primary and foreign keys, and discusses various cardinality ratios in binary relationships. Additionally, it provides examples and tasks for students to practice converting ER diagrams to relational schemas.

Uploaded by

Praket Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

ER to Relational schema

Conversion of ER diagram to Tables


• Strong entity sets
• Composite attributes
• Multivalued attributes
• Relationships sets
• Weak entity sets
Components of conversion process
• Three components of conversion process: –
• Specify schema of relation itself
• Specify primary key on the relation
• Specify any foreign key references to other relations
Strong entity sets
• Strong entity-set E with simple and single-valued attributes (a_1, a_2, …
a_n)
• Create a relational schema with same name E, and same attributes.
• Primary key of relational schema is same as primary key of entity-set.
• No foreign key references for strong entity-sets
Strong entity sets to Table

Student Table
Roll_id Name Gender Mobile_no Age
Composite
attribute to Table

Student Table

Roll_no First_name Last_name City Street House_no


Multivalued attribute
• Separate table for each multivalued attribute
• For multivalued attribute M in entity-set E
– Create a relation schema R to store M, with attribute A (single valued)
corresponding to M
– Attributes of R are: A U primary_key ( E )
– Primary key of R includes all attributes of R
– Foreign key constraint from R to E, on primary_key ( E) attributes
Multivalued
attribute to Table
Rollno AGE MOB_NO EMAILID
1 24 9877249515 [email protected]
1 24 7877249515 NULL

WRONG SOLUTION RELATIONAL TABLE


Rolln AG MOB_N MOB_N MOB_N EMAILID1 EMAILID2
SOLUTION 1 o E O_1 O_2 O_3

1 24 987724 887724 987724 [email protected] Abhay@BENNET


FIND A 9515 9515 2215 om T.com
STUDENT
WHOSE MOB
NO IS: 2 22 787724 NULL NULL ROHAN@gmail. NULL
8877249515 9515 com

3 21 787724 NULL NULL [email protected] NULL


9512

4 21 787724 NULL NULL KRISHIV@gmail. NULL


9511 com

5 21 787724 NULL NULL NULL NULL


9522
SOLUTION 2 Rollno AGE MOB_NO_1 EMAILID1

SIMPLICITY IS 1 24 9877249515, [email protected],


LOST WHILE 8877249515, [email protected]
PERFORMING, 9877242215
DELETE,UPDATE
AND SELECT
2 22 7877249515 [email protected]

3 21 7877249512 [email protected]

4 21 7877249511 [email protected]

5 21 7877249522 NULL
Multivalued Student Table
Roll_no Age
attribute to Table 1
2

Mobile Table

Roll_no Mob_no
3

Email Table

Roll_no Email_id
Relationship set
• Relationship-set R
▪ Assume all participating entity-sets are strong entity sets
▪ a_1, a_2, …, a_m is the union of all participating entitysets’ primary key attributes
▪ b_1, b_2, …, b_n are descriptive attributes on R (if any)
Relational schema for R is:
▪ { a1, a 2, …, a m} U { b1, b 2, …, b n }
▪ Primary key of R depends on R’s mapping cardinality
Relationship set
to Table

Works_in Table

Emp_no Dept_id since


1 2
Task for students

Convert into relational schema


Binary relationship with cardinality ratio
• Case-01: Binary relationship with cardinality ratio m:n
• Case-02: Binary relationship with cardinality ratio n:1
• Case-03: Binary relationship with cardinality ratio 1:n
• Case-04: Binary relationship with cardinality ratio 1:1
Case-01: Binary relationship with cardinality
ratio m:n

Tables:
Table 1
A (a1, a2)

Table 2
B (b1, b2)

Table 3
R(a1, b1)
Example on cardinality
ratio m:n

Student Table Enroll Table Courses Table After minimization of Tables

SID Name SID CID CID C_name Student (SID, Name)


S1 Ram S1 C1 C1 DBMS Enroll (SID, CID)
S2 C1 C2 OS Course (CID, C_name)
S2 David
S3 Mohan S3 C2
S4 Shyam S1 C2
S5 John S5 C1
Case-02: Binary relationship with cardinality
ratio 1:n

Tables:
Table 1
A (a1, a2)

Table 2
BR (a1, b1, b2)
Example on cardinality
ratio 1:n
Student Table Enrolls Table Courses Table After minimization of Tables

SID Name SID CID CID C_name Students (SID, Name)


S1 Ram S1 C1 C1 DBMS Course_Enroll (CID, SID, C_name)

S2 David S2 C3 C2 OS
S3 Mohan S1 C2 C3 DS
S4 Shyam S2 C4 C4 NS
S5 John S3 C5 C5 IMS
Case-03: Binary relationship with cardinality
ratio m:1

Tables:
Table 1
AR (a1, b1, a2)

Table 2
B (b1, b2)
Example on cardinality
ratio m:1
Student Table Enroll Table Course Table After minimization of Tables

SID Name SID CID CID C_name


Student_Enroll (SID, CID, Name)
S1 Ram S1 C1 C1 DBMS
Course (CID, C_name)
S2 David S2 C1 C2 OS
S3 Mohan S3 C2
S4 Shyam S4 C1
S5 John S5 C2
Case-04: Binary relationship with cardinality
ratio 1:1

Tables:
Table 1
AR (a1, b1, a2)
Table 2
B (b1, b2)

Or
Table 1
A (a1, a2)
Table 2
BR (a1, b1, b2)
Example on cardinality
ratio 1:1
Student Table Enroll Table Course Table After minimization of Tables

SID Name SID CID CID C_name


Student_Enroll (SID, CID, Name)
S1 Ram S1 C1 C1 DBMS Course (CID, C_name)
S2 David S2 C3 C2 OS
S3 Mohan S3 C2 C3 DS Or
S4 Shyam S4 C5 C4 NS Student (SID, Name)
S5 John S5 C4 C5 IMS Course_Enroll (CID, SID C_name)
One to One relationship with total
participation at one end

• A1 and B1 are primary keys of E1 and E2 respectively.


• Since E1 is in total participation, each entry in E1 is related to only one entry in E2, but not all entries
in E2 are related to an entry in E1.
• The primary key of E1 should be allowed as the primary key of the reduced table, since if the primary
key of E2 is used, it might have null values for many of its entries in the reduced table.
One to One relationship with total
participation at both end

Only one table is required.


• ARB ( a1 , a2 , b1 , b2 )
one to many relationship with total
participation at many end
• Weak entity set always appears in
association with identifying
relationship with total participation
constraint
• Here, two tables will be required-
1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )
Weak entity set
• Weak entity-sets depend on at least one strong entity-set
▪ Identifying entity-set, or owner entity-set
▪ Relationship between the two called the identifying relationship
• Weak entity-set A owned by strong entity-set B
▪ Attributes of A are { a_1, a_2, …, a_m }
▪ primary_key ( B) = { b_1, b_2, …, b_n }
▪ Relational schema for A: { a_1,a_2,…, a_m} U { b1,b 2,…, b n }
▪ Primary key of A is discriminator( A) U primary_key ( B )
▪ A has foreign key constraint on primary_key ( B)
Identifying Relationship
• Identifying relationship is many-to-one, with no descriptive attributes
• Relational schema for weak entity-set includes primary key for strong entity-
set
▪ Foreign key constraint imposed, too
▪ No need to create relational schema for identifying relationship.
Weak entity set to table

account (account_number, balance)


check (account_number, check_number, check_data, recipient, amount, memo)
Weak entity set to table contd…
Weak entity set to table contd…

student (username)
assignment (shortname, due_date, url)
submission ( username, version, shortname, submit_date, data)
MCQ

What is the min and max number of tables required to convert an ER diagram
with 2 entities and 1 relationship between them with partial participation
constraints of both entities?
• Min 1 and Max 2
• Min 1 and Max 3
• Min 2 and Max 3
• Min 2 and Max 2
MCQ

What is the min and max number of tables required to convert an ER diagram
with 2 entities and 1 relationship between them with partial participation
constraints of both entities?
• Min 1 and Max 2
• Min 1 and Max 3
• Min 2 and Max 3
• Min 2 and Max 2
MCQ

• Which of the following possible


relations will not hold if the ERD is
mapped into a relation model?
• Person (NID, Name)
• Qualification (NID, ExamID,
QualifiedDate)
• Exam (ExamID, NID, ExamName)
MCQ

Which of the following possible relations


will not hold if the ERD is mapped into a
relation model?
• Person (NID, Name)
• Qualification (NID, ExamID,
QualifiedDate)
• Exam (ExamID, NID, ExamName)
Over to You

• Minimum number of tables needed to represent the entity relationship


diagram is ___________.
• Find the attribute sets of the minimized table.
• Find the minimum number of tables required to represent the given ER
diagram in relational model
• https://www.gatevidyalay.com/er-diagrams-to-tables-practice-problems/
• https://www.gatevidyalay.com/er-diagrams-to-tables-practice-problems/
• http://homepages.inf.ed.ac.uk/libkin/teach/dbs14/ER-lecture.pdf
• https://www.geeksforgeeks.org/mapping-from-er-model-to-relational-
model/

You might also like