0% found this document useful (0 votes)
11 views50 pages

Unit-2-DAY 8 - 04 - 10

This document provides a comprehensive guide on converting an Entity-Relationship (ER) model into relational tables, outlining various data modeling techniques and constraints. It covers topics such as the representation of relations, primary and foreign keys, and the treatment of weak and multivalued entities. Additionally, it details the rules for converting different types of relationships in ER diagrams into relational schemas.

Uploaded by

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

Unit-2-DAY 8 - 04 - 10

This document provides a comprehensive guide on converting an Entity-Relationship (ER) model into relational tables, outlining various data modeling techniques and constraints. It covers topics such as the representation of relations, primary and foreign keys, and the treatment of weak and multivalued entities. Additionally, it details the rules for converting different types of relationships in ER diagrams into relational schemas.

Uploaded by

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

Quality Content for Outcome based Learning

Reduction of an ER Model to Relational


Tables
Unit 2 Day 8

Ver. No.: 1.1 Copyright © 2021, ABES Engineering College


General Guideline
© (2021) ABES Engineering College.

This document contains valuable confidential and proprietary information of ABESEC. Such confidential and
proprietary information includes, amongst others, proprietary intellectual property which can be legally protected and
commercialized. Such information is furnished herein for training purposes only. Except with the express prior
written permission of ABESEC, this document and the information contained herein may not be published,
disclosed, or used for any other purpose.

2
Copyright © 2021, ABES Engineering College
Module Objective

Describe use and apply data analysis and Modelling Techniques


i.e. data modelling

To apply Binary Relationship Constraints

Describe the fundamental Elements of ER Model

To understand the concept of Keys

To Explain the Extended E- R concepts

Convert the ER model to relational table in populated relation


database
3
Copyright © 2021, ABES Engineering College
Topics Covered

Day 5 Day 6 Day 7 Day 8

• Introduction • Constraints • Completion of • Reduction of


Case Study- on Binary ER model an ER Model
User Relationship • Reduction of to an
Requirement Types an ER Model Relational
• Basic • Keys to an Table (Cont.).
Concept of • Primary Relational • Complete
ER Model Table Relational
• Foreign key
• ER Modelling Model of
• Extended ER Case Study
• Entities
Concept
• Attributes
• Relationship

4
Copyright © 2021, ABES Engineering College
Introduction to Relational Database

A Relational database is the type of database based on


the relational model proposed by E.F. Codd in 1970.

A relational database is a collection of Relations.

5
Copyright © 2021, ABES Engineering College
Relation

Relation is a set of tuples/records (t1, t2,…, tn) where each element ti belongs to
a domain Di.

The domain is a set of values that an attribute can hold.

Example : The domain for attribute roll_no of an entity type STUDENT is the
set of all roll numbers.

These Relations are also called Tables and each Relation is assigned a unique
name in the database.

6
Copyright © 2021, ABES Engineering College
Representation of a Relation
A Relation or Table , in which a row keeps the record of an entity instance and
each column holds the values of an attribute for the complete entity set.

A software used to manage the relational database is called a Relational


Database Management System (RDBMS).
7
Copyright © 2021, ABES Engineering College
Representation of a Relation
Example : A Table below shows a Relation named STUDENT.

• It keeps a record of 6 students in six rows, which are also called tuples.
• This Relation has 11 attributes named roll_no, first_name, middle_name,
last_name, dob, gender, house_no, street_name, city, state, pin-code.

8
Copyright © 2021, ABES Engineering College
Relation Schema
A Relation schema describes the Relation (Table) structure as it includes
the Relation name, names of attributes.

Example: The Relation schema of two Relations FACULTY and COURSE can be written as:
 FACULTY (faculty_id, first_name, middle_name, last_name, designation, doj, gender, salary)
 COURSE (course_id, course_name, course_credit)

The degree or arity of a Relation is the number of attributes in a Relation schema.

Example:
The degree of Relation schema FACULTY is eight.
The degree of Relation schema COURSE is three.

9
Copyright © 2021, ABES Engineering College
Relation Instance
The snapshot of data stored in a Relation at any instant of time is called
a Relation instance.

Example: An instance of the Relation STUDENT at a particular instance has 6 entity


instance and 11 attributes.
Instances
6 Entity

10
Copyright © 2021, ABES Engineering College
Database Instance and Database Schema
The collection of data stored in the database at any instant of time is called a database
instance.

The overall design or structure of the database is called the database schema.

 When the data is initially populated in the database, it is called the initial state.
 Any kind of modification changes the state of the Relation in the database.

The state of Relations in a database can change frequently, but the schema of
the Relations in the database is not supposed to change frequently.

11
Copyright © 2021, ABES Engineering College
Database Instance and Database Schema
Example: A relational database shown in figure has four Relations
STUDENT, FACULTY, COURSE, and DEPARTMENT.

Database Schema:

12
Copyright © 2021, ABES Engineering College
Relation Model - Introduction
After designing the conceptual model of the database using an ER diagram, we
need to convert the conceptual model into the relational model.

So let’s understand what is Relational Model ?

Please Note: We are covering the Concepts of Relational Model in brief in this unit , from the perspective
of conversion of ER Model to Relational Model . The details of relational Model will be covered in Unit-3.

13
Copyright © 2021, ABES Engineering College
Relational Model
The relational model represents how data is stored in Relational Databases.

 A relational database stores data in the form of Relations (Tables).


 In the relational model, entity types and their corresponding relationships are
represented by a collection of inter-related Tables.
 Each Table is a group of columns and rows, where a column represents an attribute
of an entity type and rows represent its instance.

In the next slides , we will see the rules that are used for converting an ER diagram into
the relational tables

14
Copyright © 2021, ABES Engineering College
Tabular Representation of Regular (Strong) Entity types
For each regular (strong) entity type E in the ER schema, create a Relation R that
includes all the simple attributes of E.

The rules are:

1. A regular (strong) entity type with only simple attributes will be converted into a
single Relation (Table).
2. Attributes of the strong entity type will become the fields (column) of Relation .
3. The key attribute of the entity type will become the primary key of the Table.

Primary Key Revisit:


A Table column(s) with the following set of features can be designated as the primary key.
A Table can have one and only one primary key.
Its value can never be NULL. Its value is always unique. The value once provided cannot be
changed.

15
Copyright © 2021, ABES Engineering College
Tabular Representation of Regular (Strong) Entity types

Example: Course Entity Type has :


1. Three simple attributes: course_id , course_name ,
course_credit.
2. Key attribute : course_id

The Course entity convert into table (relation) as :

 Name of the table/relation : course


 Column names of the relation: attributes of the
entity i.e. course_id , course_name , course_credit.
 Primary key of the relation: key attribute of the
entity i.e. course_id , represented by PK against the
course_id.

16
Copyright © 2021, ABES Engineering College
Can you answer this?
research_project
researchproj_id(PK) researchproj_name sponsor_agency duration status
Please convert the below entity into relation:

department
dept_id(PK) dept_name dept_location

17
Copyright © 2021, ABES Engineering College
Tabular Representation of Weak Entity Types
For each weak entity type W with owner entity type E in the ER schema, create
a Relation R that includes all the simple attributes of W and the key attribute of the
owner entity type E.

The rules are:

1. All the attributes of the weak entity forms the columns of the table.
2. Key attribute of the weak entity type cannot form the primary key of this table.
3. The key attribute of the owner entity type is added as foreign key column in the
table.
4. This foreign key column along with weak entity key attribute column forms the
primary key (composite) of the table.

18
Copyright © 2021, ABES Engineering College
Tabular Representation of Weak Entity types
Example 1: In the figure ,

Entity type B is the weak entity type. B has


1. 2 simple attributes : b1 , b2
2. Partial key attribute : b1
3. Owner entity set of B : A
4. Key attribute of A : a1

The weak entity B convert into table (relation) B


as :
 Name of the table/relation : B
b1 (PK) b2 a1 (PK , FK)
 Column names of the relation: attributes of
B i.e. b1 , b2 , a1 (key attribute of A).
 Primary key of the relation: partial key
Primary Key (composite) of Relation B
attribute of B + key attribute of A i.e. a1 , b1

19
Copyright © 2021, ABES Engineering College
Representation of Weak Entity SECTION (Schema)
Example 2:
Weak Entity Type Section has
1. 3 attributes : section_name , max_capacity,
student_nos
2. Partial key attribute: section_name
3. Owner entity type: Department
4. Key attribute of department: dept_id

The weak entity Section convert into table (relation)


as :
 Name of the table/relation : section
 Column names of the relation: attributes of
section i.e. section_name , max_capacity,
student_nos , dept_id (key attribute of
department).
 Primary key of the relation: partial key attribute
of section + key attribute of dept i.e.
section_name , dept_id
20
Copyright © 2021, ABES Engineering College
Can you answer this?
Please convert the below entities into relation:

21
Copyright © 2021, ABES Engineering College
Tabular Representation of Multivalued Attributes
For each multivalued attribute A of entity type E, create a new Relation R. R will have A
and key attribute of E.

The Rules are:

1. This Relation R will include an column corresponding to multivalued attribute A.


2. The primary key attribute K of entity type E add as a foreign key in relation R .
3. The primary key of R is the combination of A and K.

22
Copyright © 2021, ABES Engineering College
Multivalued Attributes
Example 1: phone_no attribute of STUDENT entity type are multivalued
attributes which mean a student can have multiple phone numbers.
• The table name is the student_phone_no
• The columns are phone_no and primary key of student entity
i.e roll_no
• The primry key is roll_no and phone_no combined.

23
Copyright © 2021, ABES Engineering College
Composite Attributes
For a composite attribute A of an entity type ,we create sub-attributes from the
composite attribute and define a column for each sub attribute in the Relation.

Example: In student entity type , address is a composite attribute having house_no,


street_name, city, state, pincode as sub attributes.

So columns for address composite attribute are : house_no, street_name, city, state,
pincode

24
Copyright © 2021, ABES Engineering College
Tabular Representation of Relationship types
The conversion of relationship types depends on:

1. The cardinality ratio of the participating entity types.


2. The participation type of the entity type in the relationship type.

Regarding Cardinality Ratio , the following three cases are possible-

Case-01: Binary relationship with cardinality ratio 1:1


Case-02: Binary relationship with cardinality ratio 1:n or n:1
Case-03: Binary relationship with cardinality ratio m:n

Regarding Participation Type , it depends on Total or Partial type.

25
Copyright © 2021, ABES Engineering College
Case-01: Binary relationship with cardinality ratio
1:1
For each binary 1:1 relationship type R in the ER schema, identify the Relations S and
T corresponding to the entity types participating in R.

The rules are:


1. Choose one of the Relations say S.
2. Include the primary key of T as a foreign key in S.
3. Include all the simple attributes (or simple components of composite attributes) of the
1:1 relationship type R as attributes of S.
4. This approach is called as Foreign Key Approach.
5. Other approaches for conversion are :
 The merged relationship approach
 The cross-reference or relationship relation approach.
Note: It is better to choose an entity type with total participation in R in the role of S.

26
Copyright © 2021, ABES Engineering College
Case-01: Binary relationship with cardinality ratio 1:1
Example: In the figure , relationship type R has associated with entity type A and B with 1
: 1 cardinality ratio.

The tabular conversion will be in two ways:

Way 1: We have selected A as S.


1. AR ( a1 , a2 , b1 )
2. B ( b1 , b2 ) WAY-1
AR
Way 2: We have selected B as S. a1(PK) a2 b1
3. A ( a1 , a2 )
4. BR ( a1 , b1 , b2 ) B
b1(PK) b2

27
Copyright © 2021, ABES Engineering College
Case-01: Binary relationship with cardinality ratio 1:1
Example: Each student has to do one mini-project individually and every available mini-
project has to be opted by a student.
Cardinality- 1 : 1
Participation - Total participation of Student Entity Type and Total Participation of Mini Project Entity Type

Other Possibilities are :


1)student(roll_no (PK) , first_name, middle_name, last_name, dob,
gender, address , miniproj_id(FK) )
28
Copyright © 2021, ABES Engineering College
Case-02: Binary relationship with cardinality ratio 1:n or n:1

For each regular binary 1:N relationship type R, identify the Relation S representing the
participating entity type at the N-side of the relationship type.

The rules are:


1. Include as foreign key in S the primary key of the Relation T representing the other
entity type participating in R.
2. Include any simple attributes (or simple components of composite attributes) of the
1:N relationship type as attributes of S.
3. Other approach for conversion is
1. The Relationship relation approach

29
Copyright © 2021, ABES Engineering College
Case-02: Binary relationship with cardinality ratio 1:n or n:1

Example: In the figure , relationship type R has associated with entity type A and B with
1 : n and n : 1 cardinality ratio.

The tabular conversion will be :

Case 1:n:
n:1: Two tables will be required:
1. A ( a1 , a2 )
required:
2.
1. BR
AR (
( a1 , b1
a1 , a2 ,
, b2
b1 )
)
2. B ( b1 , b2 )
30
Copyright © 2021, ABES Engineering College
Case-02: Binary relationship with cardinality ratio 1:n or n:1

For example– A department can run zero or more courses and each course must belong
to only one department.
Cardinality: 1:M

31
Copyright © 2021, ABES Engineering College
Case -03 :Binary relationship with cardinality ratio m:n

For each binary M:N relationship type R, create a new Relation S to represent R.

The rules are:


1. Include as foreign key attributes in S the primary keys of the Relations that represent
the participating entity types.
2. Their combination will form the primary key of S.
3. Include any simple attributes of the M: N relationship type (or simple components of
composite attributes) as attributes of S.

32
Copyright © 2021, ABES Engineering College
Case-03: Binary relationship with cardinality ratio m:n

Example: In the figure , relationship type R has associated with entity type A and B with
m:n cardinality ratio.

The tabular conversion will be :

Here, three tables will be required


1. A ( a1 , a2 )
2. R ( a1 , b1 )
3. B ( b1 , b2 )
33
Copyright © 2021, ABES Engineering College
Case-03: Binary relationship with cardinality ratio m:n
For example– A faculty can teach zero or more courses and course can be taught by
zero or more faculty.
Relationship- Teaches
Cardinality- M : N

The tables are:

1. faculty (faculty_id (PK) , . . . )


2. course (course_id (PK), . . .)
3. faculty_course ( faculty_id (PK ,
FK1) , course_id (PK, FK2)

34
Copyright © 2021, ABES Engineering College
Correspondence between ER and relational model

35
Copyright © 2021, ABES Engineering College
Can you Answer?

Q. The minimum number of table needed to represent M,N,P,


R1, R2(GATE 2008)

A.2
B.3
C.4
D.5
36
Copyright © 2021, ABES Engineering College
Can you Answer ?

Q. Which of the following is a correct attribute set for one of the tables for
the correct answer to the above question?(GATE 2008)

A.{M1, M2, M3, P1}


B.{M1, P1, N1, N2}
C.{M1, P1, N1}
D.{M1, P1}
37
Copyright © 2021, ABES Engineering College
Can you Answer ?

Q. Let E1 and E2 be two entities in an E/R diagram with simple single-


valued attributes. R1 and R2 are two relationships between E1 and E2,
where R1 is one-to-many and R2 is many-to-many. R1 and R2 do not
have any attributes of their own. What is the minimum number of tables
required to represent this situation in the relational model?(GATE 2005)
A. 2
B. 3
C. 4
D. 5

38
Copyright © 2021, ABES Engineering College
Can you Answer ?

Q. 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? (GATE 2017)
A.Min 1 and max 2
B.Min 1 and max 3
C.Min 2 and max 3
D.Min 2 and max 2

39
Copyright © 2021, ABES Engineering College
Can you Answer ?

Q. In an Entity-Relationship (ER) model, suppose R is a many-to-one


relationship from entity set E1 to entity set E2. Assume that E1 and E2
participate totally in R and that the cardinality of E1 is greater that the
cardinality of E2. Which one of the following is true about R?(GATE 2018)
A. Every entity in E1 is associated with exactly one entity in E2.
B. Some entity in E1 is associated with more than one entity in E2.
C. Every entity in E2 is associated with exactly one entity in E1.
D. Every entity in E2 is associated with at most one entity in E1.

40
Copyright © 2021, ABES Engineering College
Can you Answer ?

Q. Let M and N be two entities in an E-R diagram with simple single vale
attributes. R1 and R2 are two relationships between M and N, whereas R1
is one-to-many and R2 is many-to-many. The minimum number of tables
required to represent M, N, R1 and R2 in the relational model are
_______( UGC NET 2016)
A. 4
B. 7
C. 6
D. 3

41
Copyright © 2021, ABES Engineering College
Can you Answer ?

Q. An ER model of a database consists of entity types A and B. These are


connected by a relationship R which does not have its own attribute.
Under which of the following conditions, can the relational table for R be
merged with that of A? (GATE 2017)
A. Relation R is one-to-many and the participation of A in R is total.
B. Relation R is one-to-many and the participation of A in R is partial.
C. Relation R is many-to-one and the participation of A in R is total.
D. Relation R is many-to-one and the participation of A in R is partial.

42
Copyright © 2021, ABES Engineering College
Can you Answer ?

Q. Find minimum number of tables required for converting the


following entity relationship diagram into relational database?(UGC
NET 2019)

A.2
B.4
C.3
D.5
43
Copyright © 2021, ABES Engineering College
Quality Content for Outcome based Learning

Complete Relational Model of Case Study

Ver. No.: 1.1 Copyright © 2021, ABES Engineering College


Complete Relational Model of Case Study

Relations (tables) corresponding to various entities and their relationships

45
Copyright © 2021, ABES Engineering College
Complete Relational Model of Case Study (Cont.)

Relations (tables) corresponding to various entities and their relationships

46
Copyright © 2021, ABES Engineering College
Complete Relational Model of Case Study (Cont.)

Relation (table) created due to identifying relationship between section and department

Relation (table) created due to multilayered attribute “phone_no” and “hooby” in student entity

47
Copyright © 2021, ABES Engineering College
Complete Relational Model of Case Study (Cont.)

Relations (tables) created due to M:N Cardinality among various entities

48
Copyright © 2021, ABES Engineering College
Diagram showing various Tables and relationship between them
of the case study

Diagram showing var


ious Tables and rel
ationship between t
hem of the case stu
dy.pdf

49
Copyright © 2021, ABES Engineering College
Thank You

50
Copyright © 2021, ABES Engineering College

You might also like