Introduction of ER Model
Introduction of ER Model
ER model in DBMS is the high-level data model. It stands for the Entity-relationship model
and is used to represent a logical view of the system from a data perspective. In simple words,
the entity relationship diagram is a blueprint that can used to create a database. E-R diagrams
are used to model real-world objects like a person, a car, a company and the relation between
these real-world objects.
Features of ER model
E-R diagrams are used to represent E-R model in a database, which makes them easy
to be converted into relations (tables).
E-R diagrams provide the purpose of real-world modeling of objects which makes them
intently useful.
These diagrams are very easy to understand and easy to create even by a naive user.
Entity:
It is a real-world thing which can be a person, place, or even a concept. For Example:
Department, Admin, Courses, Teachers, Students, Building, etc are some of the entities of a
School Management System.
Entity type: The entity type is a collection of the entity having similar attributes.
Entity set: is a group of entities of similar kinds. It can contain entities with attributes that
share similar values. It's collectively a group of entities of a similar type. The entity set need
not be disjoint.
In summary, an Entity is an object of a Type Entity and the set of all entities is called an entity
set.
Weak Entity – Weak entity type doesn’t have a key attribute and so we cannot uniquely
identify them by their attributes alone. Therefore, a foreign key must be used in combination
with its attributes to create a primary key. They are called Weak entity types because they can’t
be identified on their own. It relies on another powerful entity for its unique identity. A weak
entity is represented by a double-outlined rectangle in ER diagrams.
Strong entity always has a primary key. While a weak entity has a partial
discriminator key.
Strong entity is not dependent on any Weak entity depends on strong entity.
other entity.
Two strong entity’s relationship is While the relation between one strong
represented by a single diamond. and one weak entity is represented by a
double diamond.
Strong entities have either total While weak entity always has total
participation or not. participation.
Attributes:
An entity which contains a real-world property called an attribute. For Example: The entity
employee has the property like employee id, salary, age, etc.
An entity is represented by a set of attributes. Attributes are descriptive properties possessed
by each member of an entity set.
Customer is an entity and its attributes are customerid, custmername, custaddress etc.
An attribute as used in the E-R model, can be characterized by the following attribute types.
c) Derived Attribute:
Derived Attributes: An attribute that can be derived from other known attributes is known
as derived attribute.
Ex. Age of employees can be derived if you know date of birth and system date.
Age = System date – Date of birth
Stored Attributes: An attribute which cannot be derived by other known attributes is known
as stored attribute.
Ex. Date of birth of any employee.
A set of relationships of similar type is called a relationship set. Like entities, a relationship too
can have attributes. These attributes are called descriptive attributes.
For example: Consider two Entity sets, Student and Course as shown in fig below. “Enrolled-
in” is a relationship set defined on the above 2 entity sets, which denotes the association
between Student and the Course in which enrolment is made. The association as shown below.
Mapping Cardinalities:
Mapping cardinalities or cardinality ratios, express the number of entities to which another
entity
can be associated via a relationship set. Mapping cardinalities are most useful in describing
binary
relationship sets, although they can contribute to the description of relationship sets that involve
more than two entity sets. For a binary relationship set R between entity sets A and B, the
mapping
customer borrow loan
cardinalities must be one of the following:
1. One to One:
An entity in A is associated with at most one entity in B, and an entity in B is associated with
at most one entity in A.
Example: A branch, say of a bank, has one head managing the branch.
2. One to Many:
An entity in A is associated with any number of entities in B. An entity in B is associated with
at the most one entity in A.
Example: Scientist can invent many inventions, but the invention is done by the only specific
scientist.
3. Many to One:
An entity in A is associated with at most one entity in B. An entity in B is associated with any
number in A.
Example: Student enrols for only one course, but a course can have many students.
4. Many to Many:
Entities in A and B are associated with any number of entities from each other.
Example: Employee can assign by many projects and project can have many employees.
Symbols Used in ER Model
ER Model is used to model the logical view of the system from a data perspective which
consists of these symbols:
Keys
Keys are used to specify the tuples distinctly in the given relation.
Various types of keys used in relational model are – Super key, Candidate Keys, primary keys,
foreign keys.
Let us discuss them with suitable example
1) Super Key(SK): It is a set of one or more attributes within a table that can uniquely identify
each record within a table. For example - Consider the Student table as follows-
Clearly using the (RegNo) and (RollNo, Phone, Name) we can identify the records uniquely
but (Name, Marks) of two students can be same, hence this combination not necessarily help
in identifying the record uniquely.
2) Candidate Key(CK): The candidate key is a subset of superset. In other words, candidate
key is a single attribute or least or minimal combination of attributes that uniquely identify
each record in the table. For example - in above given Student table, the candidate key is
RegNo, (RollNo,Phone). The candidate key can be
Thus every candidate key is a superkey but every superkey is not a candidate key.
3) Primary Key(PK): The primary key is a candidate key chosen by the database designer to
identify the tuple in the relation uniquely. For example - Consider the following representation
of primary key in the student table
Other than the above mentioned primary key, various possible primary keys can be (RollNo),
(RollNo, Name), (RollNo, Phone)
The relation among super key, candidate key and primary can be denoted by
Candidate Key= Super Key- Primary Key
Rules for Primary Key
(i) The primary key may have one or more attributes.
(ii) There is only one primary key in the relation.
(iii) The value of primary key attribute can not be NULL.
(iv) The value of primary key attributes does not be NULL.
4) Alternate Key:The alternate key is a candidate key which is not chosen by the database
designer to uniquely identify the tubles. For example-
5) Foreign key: Foreign key is a single attribute or collection of attributes in one table that
refers to the primary key of other table.
• Thus foreign keys refers to primary key.
• The table containing the primary key is called parent table and the table containing foreign
key is called child table.
• Example-
From above example, we can see that two tables are linked. For instance, we could easily find
out that the 'Student CCC has opted for ComputerSci course
Binary Relationship
3. Ternary Relationship: When there are three entity sets participating in a relationship, the
relationship is called a ternary relationship.
4. N-ary Relationship: When there are n entities set participating in a relationship, the
relationship is called an n-ary relationship.
Make an E-R diagram having two entity sets, Customer and Item. Cardinality
Ratio is many to many because a customer can buy any number of items and same
item can be purchased by more than one customer.