Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 53

System Analysis

and Design
CSE 4004

Ms. Hansamali Paul


Visiting Lecturer
ICBT
Data modelling using the
Entity Relationship Model
The Entity Relationship Model

ER model was introduced by Peter Chenn in 1976


ER model is used for design and representation of relationships between data.
ER model describes the structure of a database with the help of diagram,
which is known as Entity Relationship Diagram/ER Diagram
It is used for designing database (ER model is a design or blueprint of a
database that can be later implemented as a database).
Components of ER model

The main components of ER model are:


Entity
Attributes
Relationships
Entity

An Entity is a “thing” or “object” in the real world that is


distinguishable from other objects.
An entity may be any object, class, person or place.
Example: In a school database, the students, teachers,
classes, courses or projects can be taken as an entity
Entities are represented by means of rectangles.
Entity

Entities have attributes that give them their identity.


Example: Students have roll. No, names and addresses
Weak Entity
An entity that cannot be uniquely identified by its own attributes and relies on
the relationship with other entity is called weak entity.
The weak entity is represented by a double rectangle.
The weak entity doesn't contain any key attribute of its own.
Weak Entity

Example: a bank account cannot be uniquely identified without


knowing the bank to which the account belong, so bank account
is a weal entity.
Entity Set

An Entity Set is a collection of similar type of entities , that share same


attributes.
Example: a Student set may contain all the students of a school;
a Teachers set may contain all the teachers of a school from all
faculties.
Attributes
An entity is represented by a set of attributes.

Attributes are used to describe the property of an entity


Example: a Student entity may have Roll_No, Name, DOB, Age,
Address, Mobile_No as attribute

For each attribute there is a set of permitted values, called domain (or range) of
that attribute.
Example: a student’s name cannot be a numeric value. It has to
be alphabetic. A student’s age cannot be negative, etc. a student roll_no
can be numeric between some range like (0 - 10000)
Attributes

Attributes are represented by Ellipse.


Attributes

Attribute Types
Simple Attributes
Composite attributes
Derived Attributes
Key Attribute.
Multi-valued Attributes
Attributes

Simple Attributes
Simple attributes are those attributes which can not be divided further.
Example: student’s age
weight

Composite Attributes
A composite attribute is made up of more than one simple attribute. Can
be divided into further parts.
Example: Name – First Name, Middle Name, Last Name
Address – street name, city, country, pincode
Attributes

Composite Attributes
Attributes

Derived Attributes

These attributes can be


derived from other attributes.
Derived attributes are
depicted by dashed ellipse.

Example: age – can be


derived from date of birth
Attributes

Multivalued Attributes
These attributes can have set of
values for a particular entity.
Represented by double-ellipse

Example: Mob_no and


Email_id are multi valued
attributes as they can take
more than one values for a
given entity.
Attributes
Key Attribute
The attribute which uniquely identifies each entity in the entity set is
called key attribute.
Key attribute is represented by an ellipse with underlying lines.
Example: Roll_no will be unique for each student.
ER Diagram Notations

Rectangles: this symbol represent entity types


Ellipses: symbol represents attributes
Diamonds: this symbol represents relationship types
Lines: it links attributes to entity types and entity types with other
relationship types
Primary key: attributes are underlined
Double Ellipses: represent multi-valued attributes
ER Diagram Notations

Entity
Relationship
Attribute
Weak Entity
Weak Entity Relationship Composite
Multivalued Attribute Attribute

Key Attribute
Relationships

A Relationship is an association/relation among entities.


Example: an employee works_at a department
a student enrolls in a course
teacher teaches student
Here, works_at, enrolls and teaches are called relationships.
Relationships
Degree of Relationship

Denotes the number of entity types that participate in a


relationship
Unary
Binary
Ternary
N-ary
Degree of Relationship

Unary Relationship
Exists when there is an association with only one entity.
Example: one person is married to only one person

.
Degree of Relationship

Binary Relationship
Exists when there is an association among two entities and is the most
common relationship degree.
Example: student is enrolled in Course
Degree of Relationship

Ternary Relationship
Exists when there is an association among three entities
Example: the university might need to record which teachers taught
which subjects in which courses.

.
Degree of Relationship

N-ary Relationship
When there are n entities set participating in a relation, the
relationship is called as n-ary relationship.

.
Relationship Constraints

Cardinality Ratio
Maximum number of relationship instances that an entity can participate
in.
Possible cardinality ratios for binary relationship are 1:1, 1:N, N:1, M:N

.
Relationship Constraints

One to One (1:1)


An entity of entity set A can be associated with at most one entity of entity set B
and an entity of entity set B can be associated with at most one entity of entity set
A.

Employee 1 manages
1 Department

1 Employee can manage maximum 1 department and 1 Department can have


maximum 1 manager
Relationship Constraints

One to One (1:1)

.
Relationship Constraints

One to Many (1:N)


An entity of entity set A can be associated with any number of entities of entity
set B and an entity of entity set B can be associated with at most one entity of
entity set A.

Employee 1 Works_for
N Department

1 Employee can works_for many departments and many Department can have
maximum of 1 Employee
Relationship Constraints

One to Many (1:N)


Example:

Scientist 1 invents
N Invention

Scientist can invent many inventions, but the invention is done by the only
specific scientist.
Relationship Constraints

One to Many (1:N)

.
Relationship Constraints

Many to One (N:1)


An entity of entity set A can be associated with at most one entity of entity set B
and an entity of entity set B can be associated any number of entities of entity set
A.

Employee N Works_for
1 Department

many Employees can works_for maximum 1 department and 1 Department can


have maximum of N Employees
Relationship Constraints

Many to One (N:1)


Example:

Student
N enroll
1 Course

Student enrolls for only one course, but a course can have many students.
.
Relationship Constraints

Many to One (N:1)

.
Relationship Constraints

Many to Many (M:N)


An entity of entity set A can be associated with any number of entities of entity
set B and an entity in entity set B can be associated any number of entities of
entity set A.

Student M studies
N Subject

Many Students can study any number of subjects and many subjects can be
studied by any number of students.
Relationship Constraints

Many to Many (M:N)


Example:

Employee
M Is N Project
assigned

Employee can assign by many projects and project can have many
employees.
.
Relationship Constraints

Many to Many (M:N)

.
Relationship Constraints

Participation Constraints
Specifies whether existence of an entity depends on its being related to another
entity.

There are two types of participation constraints


Total Participation
Partial Participation
Example

Partial Participation Total Participation

Employee Works_for Department

.partial participation is shown using one line and the total participation is shown using
two lines.
Example

Employee entity set manages Department entity set

E1
E2
. D1

.
E3 . D2

.
E4 D3
E5
E1
E2
. D1
E3 . D2

.
E4 D3
E5

Employee E1 managed D1 and E4 manages D2 and E5 manages D3. this means all the
departments should have 1 manager. So the entire department set participates in the
relationship manages. Hence we have total participation.
In the employee entity set not all employees will be managers. Only E1, E4 and E5 are
managers. So this employee set participates partially in the relationship manages. Hence
it’s a partial participation
Attributes of Relationship Types
A relationship type can have attributes
Example: HoursPerWeek of Works_On
Its value for each relationship instance describes the number of hours per week that
an Employee works on a Project
hours
.

Employee Works_for Department


Keys
A DBMS key is an attribute or set of an attribute which helps you to identify a
row (tuple1) in a relationship (table). They allow you to find the relation between
two tables. Keys help you uniquely identify a row in a table by a combination of
one or more columns in that table.

Primary Key
A primary key is a column or set of columns in a table that uniquely identifies
tuples (rows) in that table.
Keys

Primary Key
A primary key is a column or set of columns in a table that uniquely identifies
tuples (rows) in that table.
We can have license_id also as primary key
Because it is also unique.

For each entity, the primary key selection is


based on requirements and developers.
Candidate Key
A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
Except for the primary key, the remaining attributes are considered a candidate key.
The candidate keys are as strong as the primary key.
Example:In the EMPLOYEE table, id is best suited
for the primary key. The rest of the
attributes, like SSN, Passport_Number,
License_Number, etc., are considered a
candidate key.
Keys
Super Key
A super key is a set of one of more columns (attributes) to uniquely identify rows
in a table.
A super key is a superset of a candidate key.
Example: In the above EMPLOYEE table,
for(EMPLOEE_ID, EMPLOYEE_NAME), the name of
two employees can be the same, but their
EMPLYEE_ID can't be the same. Hence, this
combination can also be a key
Foreign Key
Foreign keys are the columns of a table that points to the primary key of another table.
Foreign key is used to set up a link between a table and another table existing in the
database.

Every employee works in a specific department in a company, and employee and


department are two different entities. So we can't store the department's information in the
employee table. That's why we link these two tables through the primary key of one table.
We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in
the EMPLOYEE table.

In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are
related.

We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in the EMPLOYEE
table.
In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.
Alternate Key
There may be one or more attributes or a combination of attributes that uniquely identify
each tuple in a relation.

These attributes or combinations of the attributes are called the candidate keys.
One key is chosen as the primary key from these candidate keys, and the remaining
candidate key, if it exists, is termed the alternate key.

The alternate key may or may not exist.


If there is only one candidate key in a relation, it does not have an alternate key.
Alternate Key
Example: employee relation has two attributes, Employee_Id and PAN_No, that act as
candidate keys. In this relation, Employee_Id is chosen as the primary key, so the other
candidate key, PAN_No, acts as the Alternate key.
employee relation has two attributes, Employee_Id and PAN_No, that act as candidate keys. In this relation, Employee_Id is chosen as
the primary key, so the other candidate key, PAN_No, acts as the Alternate key.
Primary Key VS Foreign Key

Primary Key Foreign Key

Helps you to uniquely identify a It is a field that is the primary key of


record in the table another table

Primary key never accepts null A foreign key may accept multiple
values null values

You can have a single primary key in You can have multiple foreign keys in
a table a table
Tables from ER Diagrams

The database can be represented


using the notations, and these
notations can be reduced to a
collection of tables.

In the database, every entity set


or relationship set can be
represented in tabular form.
Thank You

You might also like