ER MODEL
The Entity Relational Model is a model for identifying entities to be
represented in the database and representation of how those
entities are related. The ER data model specifies enterprise schema
that represents the overall logical structure of a database
graphically.
ADARSH COLLEGE NOTES
Components of ER Diagram :
ER Model consists of Entities, Attributes, and Relationships among
Entities in a Database System.
ADARSH COLLEGE NOTES
What is Entity?
An Entity may be an object with a physical existence – a particular
person, car, house, or employee – or it may be an object with a
conceptual existence – a company, a job, or a university course.
What is Entity Set?
An Entity is an object of Entity Type and
a set of all entities is called an entity set.
For Example, E1 is an entity having Entity
Type Student and the set of all students
is called Entity Set. In ER diagram, Entity
Type is represented as:
ADARSH COLLEGE NOTES
What is Strong Entity?
• A strong entity is not dependent on any other entity in the
schema. A strong entity will always have a primary key.
• Strong entities are represented by a single rectangle.
• The relationship of two strong entities is represented by a single
diamond. Various strong entities, when combined together, create
a strong entity set.
ADARSH COLLEGE NOTES
What is Weak Entity?
• A weak entity is dependent on a strong entity to ensure its
existence. Unlike a strong entity, a weak entity does not have any
primary key.
• It instead has a partial discriminator key. A weak entity is
represented by a double rectangle.
• The relation between one strong and one weak entity is
represented by a double diamond. This relationship is also known
as identifying relationship.
ADARSH COLLEGE NOTES
For Example,
• A company may store the information of dependents (Parents,
Children, Spouse) of an Employee.
• But the dependents can’t exist without the employee.
• So Dependent will be a Weak Entity Type and Employee will be
Identifying Entity type for Dependent, which means it is Strong
Entity Type.
ADARSH COLLEGE NOTES
Difference between Strong and Weak Entity
Strong Entity Weak Entity
While a weak entity has a partial
Strong entity always has a primary key.
discriminator key.
Strong entity is not dependent on any
Weak entity depends on strong entity.
other entity.
Strong entity is represented by a single Weak entity is represented by a double
rectangle. rectangle.
While the relation between one strong
Two strong entity’s relationship is
and one weak entity is represented by a
represented by a single diamond.
double diamond.
Strong entities have either total A weak entity has a total participation
participation or partial participation. constraint.
ADARSH COLLEGE NOTES
What is Attributes?
Attributes are the properties that define the entity type. For
example, Roll_No, Name, DOB, Age, Address, and Mobile_No are
the attributes that define entity type Student. In ER diagram, the
attribute is represented by an oval.
Essentially, it is a column in a table that holds data values. An entity
may contain any number of attributes. One of the attributes is
considered as the primary key. In an Entity-Relation model,
attributes are represented in an elliptical shape.
ADARSH COLLEGE NOTES
Types of Attributes :
There are different types of attributes as discussed below-
1. Simple Attribute
2. Composite Attribute
3. Single-Valued Attribute
4. Multi-Valued Attribute
5. Derived Attribute
6. Complex Attribute
7. Stored Attribute
8. Key Attribute
9. Null Attribute
10. Descriptive Attribute
ADARSH COLLEGE NOTES
1. Simple Attribute :
An attribute that cannot be further subdivided into components is a
simple attribute.
Example: The roll number of a student, the ID number of an
employee, gender, and many more.
ADARSH COLLEGE NOTES
2.Composite Attribute :
An attribute that can be split into components is a composite
attribute.
Example: The address can be further split into house number, street
number, city, state, country, and pin code, the name can also be split
into first name middle name, and last name.
ADARSH COLLEGE NOTES
3. Single-Valued Attribute :
The attribute which takes up only a single value for each entity
instance is a single-valued attribute.
Example: The age of a student, Aadhar card number.
ADARSH COLLEGE NOTES
4. Multi-Valued Attribute :
The attribute which takes up more than a single value for
each entity instance is a multi-valued attribute. And it is represented
by double oval shape.
Example: Phone number of a student: Landline and mobile.
ADARSH COLLEGE NOTES
5. Stored Attribute :
The stored attribute are those attribute which doesn’t require any
type of further update since they are stored in the database.
Example: DOB(Date of birth) is the stored attribute.
ADARSH COLLEGE NOTES
6. Derived Attribute :
An attribute that can be derived from other attributes is derived
attributes. And it is represented by dotted oval shape.
Example: Total and average marks of a student, age of an employee
that is derived from date of birth.
ADARSH COLLEGE NOTES
7. Complex Attribute :
Those attributes, which can be formed by the nesting of composite
and multi-valued attributes, are called “Complex Attributes“. These
attributes are rarely used in DBMS(DataBase Management System).
That’s why they are not so popular.
Example: Address because address contain composite value like
street, city, state, PIN code and also multivalued because one people
has more that one house address.
ADARSH COLLEGE NOTES
8. Key attribute :
Key attributes are those attributes that can uniquely identify the
entity in the entity set.
Example: Roll-No is the key attribute because it can uniquely identify
the student.
ADARSH COLLEGE NOTES
9. Null Attribute
This attribute can take NULL value when entity does not have value
for it.
Example –The ‘Net Banking Active Bin’ attribute gives weather
particular customer having net banking facility activated or not
activated.
For bank which does not offer facility of net banking in customer
table ‘Net Banking Active Bin’ attribute is always null till Net banking
facility is not activated as this attribute indicates Bank offers net
banking facility or does not offers.
ADARSH COLLEGE NOTES
10. Descriptive Attribute
Descriptive attribute give information about the relationship
set example given below. Here Start Date is the descriptive attribute
of Manages relationship.
ADARSH COLLEGE NOTES
Relationship Type and Relationship Set
A Relationship Type represents the association between entity types.
For example, ‘Enrolled in’ is a relationship type that exists between
entity type Student and Course. In ER diagram, the relationship type
is represented by a diamond and connecting the entities with lines.
ADARSH COLLEGE NOTES
A set of relationships of the same type is known as a relationship set.
The following relationship set depicts S1 as enrolled in C2, S2 as
enrolled in C1, and S3 as registered in C3.
ADARSH COLLEGE NOTES
Degree of Relations in DBMS
In DBMS, a degree of relationship represents the number of entity
types that are associated with a relationship. For example, we have
two entities, one is a student and the other is a bag and they are
connected with the primary key and foreign key. So, here we can see
that the degree of relationship is 2 as 2 entities are associating in a
relationship.
Types of degree
Now, based on the number of linked entity types, we have 4 types
of degrees of relationships.
1. Unary
2. Binary
3. Ternary
4. N-ary
ADARSH COLLEGE NOTES
Unary (Degree 1)
In this type of relationship, both the associating entity types are the
same. So, we can say that unary relationships exist when both entity
types are the same and we call them the degree of relationship is 1.
In other words, in a relation only one entity set is participating then
such type of relationship is known as a unary relationship.
Example: In a particular
class, we have many
students, there are
monitors too. So, here
class monitors are also
students. Thus, we can say
that only students are
participating here. So the
degree of such type of
relationship is 1.
ADARSH COLLEGE NOTES
Binary (Degree 2) :
In a Binary relationship, there are two types of entity associates. So,
we can say that a Binary relationship exists when there are two types
of entity and we call them a degree of relationship is 2. Or in other
words, in a relation when two entity sets are participating then such
type of relationship is known as a binary relationship. This is the most
used relationship and one can easily be converted into a relational
table.
Example: We have two entity types ‘Student’ and ‘ID’ where each
‘Student’ has his ‘ID’. So, here two entity types are associating we
can say it is a binary relationship. Also, one ‘Father’ can have many
‘daughters’ but each ‘daughter’ should belong to only one ‘father.
We can say that it is a one-to-many binary
ADARSH COLLEGE NOTES relationship.
Ternary (Degree 3)
In the Ternary relationship, there are three types of entity
associates. So, we can say that a Ternary relationship exists when
there are three types of entity and we call them a degree of
relationship is 3. Since the number of entities increases due to this, it
becomes very complex to turn E-R into a relational table. Now let’s
understand with the examples.
ADARSH COLLEGE NOTES
Example: We have three entity types ‘Teacher’, ‘Course’, and ‘Class’.
The relationship between these entities is defined as the teacher
teaching a particular course, also the teacher teaches a particular
class. So, here three entity types are associating we can say it is a
ternary relationship.
N-ary (n Degree) :
In the N-ary relationship, there are n types of entity that associates.
So, we can say that an N-ary relationship exists when there are n
types of entities. There is one limitation of the N-ary relationship, as
there are many entities so it is very hard to convert into an entity,
rational table. So, this is very uncommon, unlike binary which is very
much popular.
ADARSH COLLEGE NOTES
Example: We have 5 entities Teacher, Class, Location, Salary, Course.
So, here five entity types are associating we can say an n-ary
relationship is 5.
ADARSH COLLEGE NOTES
Cardinality in DBMS
In database management, cardinality plays an important role. Here
cardinality represents the number of times an entity of an entity set
participates in a relationship set. Or we can say that the cardinality
of a relationship is the number of tuples (rows) in a relationship.
Types of cardinality in between tables are:
1. one-to-one
2. one-to-many
3. many-to-one
4. many-to-many
ADARSH COLLEGE NOTES
Mapping Cardinalities :
• In a database, the mapping cardinality or cardinality ratio means
to denote the number of entities to which another entity can be
linked through a certain relation set.
• Mapping cardinality is most useful in describing binary relation
sets, although they can contribute to the description of relation
sets containing more than two entity sets.
ADARSH COLLEGE NOTES
Here, we will focus only on binary relation sets means we will find
the relation between entity sets A and B for the set R. So we can map
any one of following the cardinality:
1. One-to-one: In this type of cardinality mapping, an entity in A is
connected to at most one entity in B. Or we can say that a unit or
item in B is connected to at most one unit or item in A.
For example, if a
person and passport
are two identities,
then one person can
have exactly one
passport and only one
passport can be
assigned to a person.
ADARSH COLLEGE NOTES
Example:
In a particular hospital, the surgeon department has one head of
department. They both serve one-to-one relationships.
ADARSH COLLEGE NOTES
2. One-to-many:
In this type of cardinality mapping, an entity in A is associated with
any number of entities in B. Or we can say that one unit or item in B
can be connected to at most one unit or item in A.
For example, one teacher
can teach many students
at a time. But, many
teachers cannot teach a
single student at a time.
Hence, this is One-to-
Many Cardinality.
ADARSH COLLEGE NOTES
Example:
In a particular hospital, the surgeon department has multiple doctors.
They serve one-to-many relationships.
ADARSH COLLEGE NOTES
3. Many-to-one: In this type of cardinality mapping, an entity in A is
connected to at most one entity in B. Or we can say a unit or item in
B can be associated with any number (zero or more) of entities or
items in A.
An example of this Cardinality
is surgeries done by a doctor.
Many surgeries can be
performed by a single doctor.
But one surgery cannot be
performed by many doctors
at a time.
ADARSH COLLEGE NOTES
Example:
In a particular hospital, multiple surgeries are done by a single
surgeon. Such a type of relationship is known as a many-to-one
relationship.
ADARSH COLLEGE NOTES
4. Many-to-many: In this type of cardinality mapping, an entity in A
is associated with any number of entities in B, and an entity in B is
associated with any number of entities in A.
For example, in an IT
company, many software
engineers can work on many
projects, and many projects
can be handled by multiple
people in the company.
ADARSH COLLEGE NOTES
Example:
In a particular company, multiple people work on multiple projects.
They serve many-to-many relationships.
ADARSH COLLEGE NOTES
High Cardinality and Low Cardinality
• The extent of cardinality is described by the number of unique
values that exist in the database.
• High Cardinality refers to the higher number of unique values in
the table while low cardinality means less number of unique
values in the table.
• In other words, if there are lower numbers of unique values in the
dataset, there are more chances that the value will be repeated.
Thus Cardinality is low.
• On the other hand, if there are more unique values in the dataset,
there are more chances that the values will vary. Thus Cardinality
is high.
ADARSH COLLEGE NOTES
ADARSH COLLEGE NOTES
Question 1: University Database
A university wants to design a database to manage its courses,
students, and instructors. The following are the requirements:
• Each course has a unique course code, course title, and number of
credits.
• Each student has a unique student ID, name, and major.
• Each instructor has a unique instructor ID, name, and department.
• Students can enroll in multiple courses, and each course can have
multiple students.
• Each course is taught by only one instructor, but an instructor can
teach multiple courses.
Tasks:
Identify the entities.
Identify the relationships.
Draw the ER diagram.
ADARSH COLLEGE NOTES
Question 2: Library Management System
A library wants to design a database to keep track of books, members,
and borrowing details. The requirements are as follows:
• Each book has a unique ISBN, title, author, and publication year.
• Each member has a unique member ID, name, address, and phone
number.
• Each member can borrow multiple books, and each book can be
borrowed by multiple members, but not simultaneously.
• Each borrowing event should record the borrowing date and the
return date.
Tasks:
Identify the entities.
Identify the relationships.
Draw the ER diagram.
ADARSH COLLEGE NOTES
Question 3: Online Shopping System
An online shopping platform needs to design a database to manage
its products, customers, and orders. The requirements are:
• Each product has a unique product ID, name, description, and
price.
• Each customer has a unique customer ID, name, email, and
shipping address.
• Customers can place multiple orders, and each order can contain
multiple products.
• Each order should record the order date and total amount.
Tasks:
Identify the entities.
Identify the relationships.
Draw the ER diagram.
ADARSH COLLEGE NOTES
Reduction E-R diagrams to tables
Entity relationship diagrams serve as a visual starting point for
database architecture, as well as a tool for determining information
system requirements in an organization.
After designing an ER Diagram :
• ER diagram is converted into the tables in relational model.
• This is because relational models can be easily implemented by
RDBMS like MySQL , Oracle etc.
ADARSH COLLEGE NOTES
Conversion of ER diagrams to tables
Follow the steps given below for the conversion of the ER diagrams to
tables in the database management system (DBMS) −
Step 1 − Conversion of strong entities
• For each strong entity create a separate table with the same
name.
• Includes all attributes, if there is any composite attribute divided
into simple attributes and has to be included.
• Ignore multivalued attributes at this stage.
• Select the p key for the table.
ADARSH COLLEGE NOTES
Step 2 : Converting weak entity
• Create a separate table with the very same name for each weak
entity.
• Include all attributes in your list.
• The weak entity includes the P key of a strong entity as a foreign
key.
• Declare the weak entity’s P key as a combination of foreign key as
well as decimator attribute.
Step 3 : Converting one-to-one relationship
• Modify either the A or B side of each one-to-one connection, say
A and B, to add the P key of the opposite side as a foreign key.
• If A or B has 100% participation, then the table should be
modified.
• Include attributes in the modified table if a relationship contains
them.
ADARSH COLLEGE NOTES
Step 4 : Converting one-to-many relationship
• Modify the M side of each one-to-many relation to include the P
key of one of the sides as a foreign key.
• If your relationships have attributes, make sure to mention them
as well.
Step 5 : Converting many-to-many relationship
• Create a new table for each many-to-many relationship, using the
P key from the M side and the N side as foreign keys.
• Declare P for the new table’s foreign key combination.
• If your relationships have properties, insert those in the new
table as well.
ADARSH COLLEGE NOTES
Step 6 : Converting multivalued attributes
• Create a separate table for each multivalued attribute and use the
current table’s P key as a foreign key.
• P keys are created by combining a foreign key and a multivalued
attribute.
Step 7 : Converting n-ary relationship
• Create a separate table for each n-ary relationship and then include
the P key of all the entities as a foreign key.
• Declare the P key as a combination of foreign keys.
Table
The following is the outcome of a successful conversion:
Scheme : Works in ( Emp No , Dept id , since )
Emp no Dept id since
ADARSH COLLEGE NOTES
Rule-01: For Strong Entity Set With Only Simple Attributes-
• Attributes of the table will be the attributes of the entity set.
• The primary key of the table will be the key attribute of the
entity set.
gender
Roll NO Name Gender
ADARSH COLLEGE NOTES
Schema : Student (Roll_no, Name , Gender
Rule-02: For Strong Entity Set With Composite Attributes-
• A strong entity set with any number of composite attributes will
require only one table in relational model.
• While conversion, simple attributes of the composite attributes are
taken into account and not the composite attribute itself.
ADARSH COLLEGE NOTES
Rule-03: For Strong Entity Set With Multi Valued Attributes-
A strong entity set with any number of multi valued attributes will
require two tables in relational model.
• One table will contain all the simple attributes with the primary
key.
• Other table will contain the primary key and all the multi valued
attributes.
ADARSH COLLEGE NOTES
Rule-04: Translating Relationship Set into a Table-
A relationship set will require one table in the relational model.
Attributes of the table are-
• Primary key attributes of the participating entity sets
• Its own descriptive attributes if any.
If we consider the
overall ER diagram,
three tables will be
required in
relational model-
• One table for the
entity set
“Employee”
• One table for the
entity set
“Department”
ADARSH COLLEGE NOTES
Enhanced ER Model
• Today the complexity of the data is increasing so it becomes more
and more difficult to use the traditional ER model for database
modeling.
• To reduce this complexity of modeling we have to make
improvements or enhancements to the existing ER model to make
it able to handle the complex application in a better way.
• Enhanced entity-relationship diagrams are advanced database
diagrams very similar to regular ER diagrams which represent the
requirements and complexities of complex databases.
• It is a diagrammatic technique for displaying the Sub Class and
Super Class; Specialization and Generalization; Union or Category;
Aggregation etc.
ADARSH COLLEGE NOTES
Transform ERD to DATABASE SCHEMA
ADARSH COLLEGE NOTES
Relational Schema
ADARSH COLLEGE NOTES
Database Schema
CAR
CUSTOMER
CAR_ID ( INT )
SERIAL_NUMBER(INT) CUSTOMERID ( INT )
MODEL_NO(INT) NAME(INT)
COLOR(VARCHAR) PHONENUMBER(INT)
YEAR(DATE) ADDRESS(VARCHAR)
COUNTRY(DATE)
CITY
EMPLOYEE
EMPID ( INT ) INVOICE
NAME(VARCHAR)
ADDRESS(VARCHAR) INVOICEID ( INT )
QUALIFICATION(VARCHAR) DATE (DATE)
ADARSH COLLEGE NOTES
CAR
ZERO CUSTOMER
TO
CAR_ID ( INT ) MANY
CUSTOMERID ( INT )
SERIAL_NUMBER(INT)
NAME(INT)
MODEL_NO(INT)
PHONENUMBER(INT)
COLOR(VARCHAR) ONE
ADDRESS(VARCHAR)
YEAR(DATE)
COUNTRY(DATE)
ZERO TO CITY
MANY
ONE
SELL
HAS
ONE
EMPLOYEE MANY
INVOICE
EMPID ( INT )
NAME(VARCHAR) HAS INVOICEID ( INT )
ADDRESS(VARCHAR) DATE (DATE)
QUALIFICATION(VARCHAR) ONE MANY
ADARSH COLLEGE NOTES
ADARSH COLLEGE NOTES