Unit-2-DAY 8 - 04 - 10
Unit-2-DAY 8 - 04 - 10
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
4
Copyright © 2021, ABES Engineering College
Introduction to Relational Database
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.
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.
• 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)
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.
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.
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.
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.
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.
15
Copyright © 2021, ABES Engineering College
Tabular Representation of Regular (Strong) Entity types
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.
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 ,
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
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.
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.
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:
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.
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.
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
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.
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.
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.
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.
34
Copyright © 2021, ABES Engineering College
Correspondence between ER and relational model
35
Copyright © 2021, ABES Engineering College
Can you Answer?
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)
38
Copyright © 2021, ABES Engineering College
Can you Answer ?
39
Copyright © 2021, ABES Engineering College
Can you Answer ?
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 ?
42
Copyright © 2021, ABES Engineering College
Can you Answer ?
A.2
B.4
C.3
D.5
43
Copyright © 2021, ABES Engineering College
Quality Content for Outcome based Learning
45
Copyright © 2021, ABES Engineering College
Complete Relational Model of Case Study (Cont.)
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.)
48
Copyright © 2021, ABES Engineering College
Diagram showing various Tables and relationship between them
of the case study
49
Copyright © 2021, ABES Engineering College
Thank You
50
Copyright © 2021, ABES Engineering College