Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Entity Relationship Data Modelling

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

ENTITY RELATIONSHIP DATA MODELLING

The ER model defines the conceptual view of a database. It works around real-world
entities and the associations among them. At view level, the ER model is considered a
good option for designing databases.

Entity

An entity can be a real-world object, either animate or inanimate, that can be easily
identifiable. For example, in a school database, students, teachers, classes, and courses
offered can be considered as entities. All these entities have some attributes or
properties that give them their identity.

An entity set is a collection of similar types of entities. An entity set may contain entities
with attribute sharing similar values. For example, a Students set may contain all the
students of a school; likewise a Teachers set may contain all the teachers of a school
from all faculties. Entity sets need not be disjoint.

Attributes

Entities are represented by means of their properties, called attributes. All attributes
have values. For example, a student entity may have name, class, and age as attributes.

There exists a domain or range of values that can be assigned to attributes. For example,
a student's name cannot be a numeric value. It has to be alphabetic. A student's age
cannot be negative, etc.

Types of Attributes

 Simple attribute − Simple attributes are atomic values, which cannot be divided
further. For example, a student's phone number is an atomic value of 10 digits.
 Composite attribute − Composite attributes are made of more than one simple
attribute. For example, a student's complete name may have first_name and
last_name.
 Derived attribute − Derived attributes are the attributes that do not exist in the
physical database, but their values are derived from other attributes present in
the database. For example, average_salary in a department should not be saved
directly in the database, instead it can be derived. For another example, age can
be derived from data_of_birth.
 Single-value attribute − Single-value attributes contain single value. For
example − Social_Security_Number.
 Multi-value attribute − Multi-value attributes may contain more than one
values. For example, a person can have more than one phone number,
email_address, etc.

1
These attribute types can come together in a way like −

 simple single-valued attributes


 simple multi-valued attributes
 composite single-valued attributes
 composite multi-valued attributes

Entity-Set and Keys

Key is an attribute or collection of attributes that uniquely identifies an entity among


entity set.

For example, the roll_number of a student makes him/her identifiable among students.

 Super Key − A set of attributes (one or more) that collectively identifies an entity
in an entity set.
 Candidate Key − A minimal super key is called a candidate key. An entity set
may have more than one candidate key.
 Primary Key − A primary key is one of the candidate keys chosen by the
database designer to uniquely identify the entity set.

Relationship

The association among entities is called a relationship. For example, an employee


works_at a department, a student enrolls in a course. Here, Works_at and Enrolls are
called relationships.

Relationship Set

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.

Degree of Relationship

The number of participating entities in a relationship defines the degree of the


relationship.

 Binary = degree 2
 Ternary = degree 3
 n-ary = degree

Mapping Cardinalities

2
Cardinality defines the number of entities in one entity set, which can be associated
with the number of entities of other set via relationship set.

 One-to-one − One entity from entity set A can be associated with at most one
entity of entity set B and vice versa.

 One-to-many − One entity from entity set A can be associated with more than
one entities of entity set B however an entity from entity set B, can be associated
with at most one entity.

 Many-to-one − More than one entities from entity set A can be associated with at
most one entity of entity set B, however an entity from entity set B can be
associated with more than one entity from entity set A.

3
 Many-to-many − One entity from A can be associated with more than one entity
from B and vice versa.

ER Model is represented by means of an ER diagram. Any object, for example, entities,


attributes of an entity, relationship sets, and attributes of relationship sets, can be
represented with the help of an ER diagram.

Entity

Entities are represented by means of rectangles. Rectangles are named with the entity
set they represent.

Attributes

4
Attributes are the properties of entities. Attributes are represented by means of ellipses.
Every ellipse represents one attribute and is directly connected to its entity (rectangle).

If the attributes are composite, they are further divided in a tree like structure. Every
node is then connected to its attribute. That is, composite attributes are represented by
ellipses that are connected with an ellipse.

Multivalued attributes are depicted by double ellipse.

5
Derived attributes are depicted by dashed ellipse.

Relationship

Relationships are represented by diamond-shaped box. Name of the relationship is


written inside the diamond-box. All the entities (rectangles) participating in a
relationship, are connected to it by a line.

Binary Relationship and Cardinality

6
A relationship where two entities are participating is called a binary relationship.
Cardinality is the number of instance of an entity from a relation that can be associated
with the relation.

 One-to-one − When only one instance of an entity is associated with the


relationship, it is marked as '1:1'. The following image reflects that only one
instance of each entity should be associated with the relationship. It depicts one-
to-one relationship.

 One-to-many − When more than one instance of an entity is associated with a


relationship, it is marked as '1:N'. The following image reflects that only one
instance of entity on the left and more than one instance of an entity on the right
can be associated with the relationship. It depicts one-to-many relationship.

 Many-to-one − When more than one instance of entity is associated with the
relationship, it is marked as 'N:1'. The following image reflects that more than
one instance of an entity on the left and only one instance of an entity on the
right can be associated with the relationship. It depicts many-to-one relationship.

7
 Many-to-many − The following image reflects that more than one instance of an
entity on the left and more than one instance of an entity on the right can be
associated with the relationship. It depicts many-to-many relationship.

Participation Constraints

 Total Participation − Each entity is involved in the relationship. Total


participation is represented by double lines.
 Partial participation − Not all entities are involved in the relationship. Partial
participation is represented by single lines.

ER DIAGRAMS

8
ER Diagram stands for Entity Relationship Diagram, also known as ERD is a diagram
that displays the relationship of entity sets stored in a database. In other words, ER
diagrams help to explain the logical structure of databases. ER diagrams are created
based on three basic concepts: entities, attributes and relationships.

ER diagrams are visual tools that are helpful to represent the ER model.

ER Diagrams contain different symbols that use rectangles to represent entities, ovals to
define attributes and diamond shapes to represent relationships.

Why use ER Diagrams?

Here, are prime reasons for using the ER Diagram

 Helps you to define terms related to entity relationship modeling


 Provide a preview of how all your tables should connect, what fields are going to
be on each table
 Helps to describe entities, attributes, relationships
 ER diagrams are translatable into relational tables which allows you to build
databases quickly
 ER diagrams can be used by database designers as a blueprint for implementing
data in specific software applications
 The database designer gains a better understanding of the information to be
contained in the database with the help of ERP diagram
 ERD Diagram allows you to communicate with the logical structure of the
database to users

ER Diagrams Symbols & Notations

Entity Relationship Diagram Symbols & Notations mainly contains three basic
symbols which are rectangle, oval and diamond to represent relationships between
elements, entities and attributes. There are some sub-elements which are based on main
elements in ERD Diagram. ER Diagram is a visual representation of data that describes
how data is related to each other using different ERD Symbols and Notations.

Following are the main components and its symbols in ER Diagrams:

 Rectangles: This Entity Relationship Diagram symbol represents entity types


 Ellipses : Symbol represent attributes
 Diamonds: This symbol represents relationship types
 Lines: It links attributes to entity types and entity types with other relationship
types

9
 Primary key: attributes are underlined
 Double Ellipses: Represent multi-valued attributes

ER
Diagram Symbols

Components of the ER Diagram

This model is based on three basic concepts:

 Entities
 Attributes
 Relationships

ER Diagram Examples

For example, in a University database, we might have entities for Students, Courses,
and Lecturers. Students entity can have attributes like Rollno, Name, and DeptID. They
might have relationships with Courses and Lecturers.

How to Create an Entity Relationship Diagram (ERD)

Now in this ERD Diagram Tutorial, we will learn how to create an ER Diagram.
Following are the steps to create an ER Diagram:

Steps to Create an ER Diagram

Let’s study them with an Entity Relationship Diagram Example:

10
In a university, a Student enrolls in Courses. A student must be assigned to at least one
or more Courses. Each course is taught by a single Professor. To maintain instruction
quality, a Professor can deliver only one course

Step 1) Entity Identification

We have three entities

 Student
 Course
 Professor

Step 2) Relationship Identification

We have the following two relationships

 The student is assigned a course


 Professor delivers a course

Step 3) Cardinality Identification

For them problem statement we know that,

 A student can be assigned multiple courses


 A Professor can deliver only one course

11
Step 4) Identify Attributes

You need to study the files, forms, reports, data currently maintained by the
organization to identify attributes. You can also conduct interviews with various
stakeholders to identify entities. Initially, it’s important to identify the attributes
without mapping them to a particular entity.

Once, you have a list of Attributes, you need to map them to the identified entities.
Ensure an attribute is to be paired with exactly one entity. If you think an attribute
should belong to more than one entity, use a modifier to make it unique.

Once the mapping is done, identify the primary Keys. If a unique key is not readily
available, create one.

Entity Primary Key Attribute

Student Student_ID StudentName

Professor Employee_ID ProfessorName

Course Course_ID CourseName

12
For Course Entity, attributes could be Duration, Credits, Assignments, etc. For the sake
of ease we have considered just one attribute.

Step 5) Create the ERD Diagram

A more modern representation of Entity Relationship Diagram Example

Best Practices for Developing Effective ER Diagrams

Here are some best practice or example for Developing Effective ER Diagrams.

 Eliminate any redundant entities or relationships


 You need to make sure that all your entities and relationships are properly
labeled
 There may be various valid approaches to an ER diagram. You need to make
sure that the ER diagram supports all the data you need to store
 You should assure that each entity only appears a single time in the ER diagram
 Name every relationship, entity, and attribute are represented on your diagram
 Never connect relationships to each other
 You should use colors to highlight important portions of the ER diagram

13

You might also like