0% found this document useful (0 votes)
18 views73 pages

Understanding Entity-Relationship Diagrams

An entity-relationship diagram (ERD) is a data modeling technique used to represent the entity framework infrastructure. The ERD shows entities, attributes, and relationships. Creating an ERD involves identifying entities, determining relationships between entities, and analyzing relationship cardinality.

Uploaded by

221104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views73 pages

Understanding Entity-Relationship Diagrams

An entity-relationship diagram (ERD) is a data modeling technique used to represent the entity framework infrastructure. The ERD shows entities, attributes, and relationships. Creating an ERD involves identifying entities, determining relationships between entities, and analyzing relationship cardinality.

Uploaded by

221104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

WEEK # 8

SOFTWARE ENGINEERING
DR. SYED ATIF ALI SHAH

DEPARTMENT OF COMPUTER SCIENCE


AIR UNIVERSITY, ISLAMABAD.
[Link]@[Link]
Entity-Relationship Diagram
(ERD)

Dr. Syed Atif Ali Shah 2


An entity-relationship diagram (ERD) is :

a data modeling technique that graphically


illustrates an information system’s entities and
the relationships between those entities.

a conceptual and representational model of


data used to represent the entity framework
infrastructure.

Dr. Syed Atif Ali Shah 3


Steps involved in creating an ERD include:

1. Identifying and defining the entities.

2. Determining all interactions between the entities.

3. Analyzing the nature of interactions/determining the cardinality of


the relationships.

4. Creating the ERD.


Dr. Syed Atif Ali Shah 4
used as a high-level
logical data model,
crucial to creating a
which is useful in
good database design.
developing a conceptual
design for databases.

Dr. Syed Atif Ali Shah 5


Entity
An entity is a real-world item or concept that
exists on its own.

Entities are equivalent to database tables in


a relational database, with each row of the
table representing an instance of that entity.
Dr. Syed Atif Ali Shah 6
Attribute

• An attribute of an entity is a particular property that describes the


entity.

Relationship

• A relationship is the association that describes the interaction between


entities.

Cardinality

• in the context of ERD, is the number of instances of one entity that can,
or must, be associated with each instance of another entity. In general,
there may be one-to-one, one-to-many, or many-to-many relationships.

Dr. Syed Atif Ali Shah 7


Employee Entity Department Entity

Employee Attribute : Department Attribute :

employee number department number


name name
Department number
department
Employee 1
department number
employee number
name
name
department number M
Dr. Syed Atif Ali Shah 8
2 Components of or ERD is converted
E-R Diagram to the database.
Each entity in the ERD
Entity relational diagram (ER
corresponds to a table in the
Diagram) is used to represent
database.
the requirement analysis at the
conceptual design stage.
The attributes of any an entity
correspond to field of a table.

the database is designed from


the ERD The ERD is converted to the
database.

Dr. Syed Atif Ali Shah 9


The elements of an ERD are:

ENTITIES
They are typically nouns
Entities are objects or concepts that
(customer, supervisor, location, or
represent important data.
promotion).
Dr. Syed Atif Ali Shah 10
Strong entities exist independently from
other entity types. They always possess
one or more attributes that uniquely
distinguish each occurrence of the entity.
Weak entities depend on some other entity type. They don't
possess unique attributes (also known as a primary key) and
have no meaning in the diagram without depending on
another entity. This other entity is known as the owner.
Associative entities are entities that associate
the instances of one or more entity types. They
also contain attributes that are unique to the
relationship between those entity instances.
Dr. Syed Atif Ali Shah 11
Dr. Syed Atif Ali Shah 12
Entity Weak Associative
Entity Entity

Dr. Syed Atif Ali Shah 13


2. RELATIONSHIPS
Relationships are meaningful associations
between or among entities.

They are usually verbs, e.g. assign, associate,


or track.

A relationship provides useful information that


could not be discerned with just the entity types.
Dr. Syed Atif Ali Shah 14
Weak relationships, or identifying
relationships, are connections that exist
between a weak entity type and its
owner.
Ternary Relationship, Relationship of
degree three.

Dr. Syed Atif Ali Shah 15


Weak
Relationship Relationship

Dr. Syed Atif Ali Shah 16


3. ATTRIBUTES

➢ Attributes are characteristics of either an entity, a many-to-many


relationship, or a one-to-one relationship.

Attribute

Dr. Syed Atif Ali Shah 17


Multivalued attributes are those that are capable of taking on
more than one value.
.

Multivalued
Attributes

Dr. Syed Atif Ali Shah 18


➢ Derived attributes are attributes whose value can be calculated from
related attribute values.

Derived
Attributes

Dr. Syed Atif Ali Shah 19


➢ Composite attributes are represented by ellipses that are connected
with an ellipse. they are further divided in a tree like structure. Every
node is then connected to its attribute

Attribute

composite
Attribute

Attribute

Dr. Syed Atif Ali Shah 20


➢ Key attribute represents the main characteristic of an Entity. It is used
to represent Primary key. Ellipse with underlying lines represent Key
Attribute.

Key
Attribute

Dr. Syed Atif Ali Shah 21


3. Binary Relationship and Cardinality

Binary relationship : A relationship where two entities are participating.

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.

Dr. Syed Atif Ali Shah 22


The following image reflects that only one instance of each entity should
be associated with the relationship. It depicts one-to-one relationship.

1 1
Entity Relationship Entity

Dr. Syed Atif Ali Shah 23


▪ 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.

1 N
Entity Relationship Entity

Dr. Syed Atif Ali Shah 24


▪ 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.

N 1
Entity Relationship Entity

Dr. Syed Atif Ali Shah 25


▪ 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.

N N
Entity Relationship Entity

Dr. Syed Atif Ali Shah 26


Customer-name Customer-street loan-number amount

Customer-id Customer-city

customer borrower loan

Figure 4.1 E-R diagram corresponding to customers and loans

Dr. Syed Atif Ali Shah 27


The relationship set borrower may be many-to-many, one-to-many, many-
to-one, or one-to-one.
To distinguish among these types, we draw either a directed line (→)or an
undirected line (—) between the relationship set and the entity set in
question.

Dr. Syed Atif Ali Shah 28


• A directed line (→) from the relationship set borrower to the entity set
loan specifies that borrower is either a one-to-one or many-to-one
relationship set, from customer to loan, borrower cannot be a many-to-
many or a one-to-many relationship set from customer to loan

Customer-name Customer-street loan-number amount

Customer-id Customer-city

borrower 1
customer loan

Dr. Syed Atif Ali Shah 29


An undirected line (—) from the relationship set borrower to the entity
set loan specifies that borrower is either a many-to-many or one-to-many
relationship set from customer to loan.

Customer-name Customer-street loan-number amount

Customer-id Customer-city

N
customer borrower loan

Dr. Syed Atif Ali Shah 30


If the relationship set borrower were one-to-many, from customer to
loan, then the line from borrower to customer would be directed, with an
arrow pointing to the customer entity set

Customer-name Customer-street loan-number amount

Customer-id Customer-city

1 N
customer borrower loan

Dr. Syed Atif Ali Shah 31


if the relationship set borrower were many-to-one from customer to loan,
then the line from borrower to loan would have an arrow pointing to the
loan entity set
Customer-name Customer-street loan-number amount

Customer-id Customer-city

N 1
customer borrower loan

Dr. Syed Atif Ali Shah 32


Finally, if the relationship set borrower were one-to-one, then both lines
from borrower would have arrows
Customer-name Customer-street loan-number amount

Customer-id Customer-city

1 1
customer borrower loan

Dr. Syed Atif Ali Shah 33


middle-name

Last- name
First- name

name
street
city

address
Customer-id state

customer

zip-code

Phone-number date-of-birth age

Dr. Syed Atif Ali Shah 34


title level

branch-city
job

employee-name street branch-name assets

employee-id city

employee work-on branch

Dr. Syed Atif Ali Shah 35


• We can represent a database that
conforms to an E-R database
schema by a collection of tables.
5 • For each entity set and for each
Reduction relationship set in the database,
of an E-R there is a unique table to which we
Schema to assign the name of the
Tables corresponding entity set or
relationship set.
• Each table has multiple columns,
each of which has a unique name.
Dr. Syed Atif Ali Shah 36
Both the E-R model and the relational-database model are:

• abstract, logical representations of real-world enterprises.

Because the two models employ similar design principles, we


can convert an E-R design into a relational design.

Converting a database representation from an E-R diagram to a


table format is the way we arrive at a relational-database
design from an E-R diagram.
Dr. Syed Atif Ali Shah 37
The constraints specified
Although important
in an E-R diagram, such as
differences exist between
primary keys and
a relation and a table,
cardinality constraints, are
informally, a relation can
mapped to constraints on
be considered to be a
the tables generated from
table of values.
the E-R diagram.

Dr. Syed Atif Ali Shah 38


Example :
There is an entity:

customer-schema=(customer-id,name,address,city-state-
ZIP,discount)

[Link] an entity to a relation – E/R Diagram.

[Link] an entity to a relation – relational .

Dr. Syed Atif Ali Shah 39


Address

name City-state-zip

Discount
Customer-id

customer

Customer –ID Name Address City –State-Zip Discount

1273 Contemporary Designs 123 Oak St. Austin,TX2888 5%

6390 Casual Comer 18 Hoosier Dr. Bloomington ,IN5482 3%


Dr. Syed Atif Ali Shah 40
DFD
▪ What are Data Flow Diagrams (DFDs)?
▪ Why they are useful?
▪ How are they developed?
▪ How to level DFDs?
▪ Good style conventions in developing DFDs
▪ Difference between Logical and Physical DFDs
▪ Tools available to draw DFDs

Dr. Syed Atif Ali Shah 41


Flow-Oriented Modeling
Represents how data objects are transformed at they move through
the system.

Data flow diagram (DFD) is the diagrammatic form that is used.

Considered by many to be an “old school” approach, but continues to


provide a view of the system that is unique—it should be used to
supplement other analysis model elements.

Dr. Syed Atif Ali Shah 42


The Flow Model
Every computer-based system is an information transform ....

computer
input based output
system

Dr. Syed Atif Ali Shah 43


Data Flow Diagrams
WHAT ARE
DATA FLOW
DIAGRAMS?
• External entities from which the data flows
DFDs models and where results terminate
the system by • Processes which transform data flows
depicting • Data stores from which the data are read or
into which data are written by the processes.

Dr. Syed Atif Ali Shah 44


Flow Modeling Notation

External Entity

Process

Data flow

Data store

Dr. Syed Atif Ali Shah 45


External Entity

A producer or consumer of data

Examples: a person, a device, a sensor


Another example: computer-based system

Data must always originate somewhere and must always be sent to


something

Dr. Syed Atif Ali Shah 46


Process

A data transformer (changes input to output)

Examples: compute taxes, determine area, format report, display graph

Data must always be processed in some way to achieve system


function

Dr. Syed Atif Ali Shah 47


Data Flow

Data flows through a system, beginning as input and transformed into


output.
base
compute
triangle area

height area

Dr. Syed Atif Ali Shah 48


Data Stores

Data is often stored for later use.

sensor #
sensor #, type,
look-up location, age
sensor
report required data
type,
location, age
sensor number

sensor data

Dr. Syed Atif Ali Shah 49


DFD Rules and Tips
Each process should have at least one input and an output.

Each data store should have at least one data flow in and
one data flow out.

Data stored in a system must go through a process.

All processes in a DFD go to another process or a data


store.
Dr. Syed Atif Ali Shah 50
DFD levels and layers:
From context diagrams to pseudocode

A data flow diagram can


dive into progressively DFD levels are
more detail by using numbered 0, 1 or 2, and
levels and layers, occasionally go to even
zeroing in on a particular Level 3 or beyond.
piece.

Dr. Syed Atif Ali Shah 51


DFD 0
DFD Level 0 is also called a Context Diagram. It’s a basic
overview of the whole system or process being analyzed or
modeled.

It’s designed to be an at-a-glance view, showing the system as a


single high-level process, with its relationship to external
entities.

It should be easily understood by a wide audience, including


stakeholders, business analysts, data analysts and developers.

Dr. Syed Atif Ali Shah 52


DFD 0

Dr. Syed Atif Ali Shah 53


DFD 1

DFD Level 1 provides a more detailed breakout


of pieces of the Context Level Diagram.

You will highlight the main functions carried out


by the system, as you break down the high-level
process of the Context Diagram into its sub-
processes.
Dr. Syed Atif Ali Shah 54
DFD-1

Dr. Syed Atif Ali Shah 55


DFD 2
DFD Level 2 then goes one step
deeper into parts of Level 1.

It may require more text to reach the


necessary level of detail about the
system’s functioning.
Dr. Syed Atif Ali Shah 56
DFD-2

Dr. Syed Atif Ali Shah 57


DFD 3,4
Progression to Levels 3, 4 and beyond is
possible, but going beyond Level 3 is
uncommon.

Doing so can create complexity that


makes it difficult to communicate,
compare or model effectively.
Dr. Syed Atif Ali Shah 58
Logical DFD vs. Physical DFD
A Logical DFD visualizes the data flow that is essential for a
business to operate. It focuses on the business and the
information needed, not on how the system works or is
proposed to work.

A Physical DFD shows how the system is actually


implemented now, or how it will be. For example, in a Logical
DFD, the processes would be business activities, while in a
Physical DFD, the processes would be programs and manual
procedures.
Dr. Syed Atif Ali Shah 59
0-Level DFD
- Level 0 is over simplification of the data flow
1-Level DFD
- Level 1 shows the main functions and storage points
2-Level DFD
- Level 2 shows the specific functions of how the system functions
Example-5

Context Diagram for Airline


Reservation System

Dr. Syed Atif Ali Shah 63


Level One Data Flow
Diagram for Reservation
Process

Dr. Syed Atif Ali Shah 64


Example: Airline reservation

Dr. Syed Atif Ali Shah 65


DFD Example 1: Payroll

Dr. Syed Atif Ali Shah 66


DFD Example 2: Old Car Mart
• Buys and sells old cars; has large number in stock: different models,
make, year,colors,…
• Does some repairs for adding value; records kept; has own garage
• Advertise in news papers
• Salesmen hired on commission basis to handle customers, negotiate,
etc.
• Needs to take stocks; prepare summary of sales, profits, etc; pay
salesmen
Prepare DFD

Dr. Syed Atif Ali Shah 67


Dr. Syed Atif Ali Shah 68
Example 3: Book Supplier
• Supplies books to customers; no stocks maintained; books
sourced directly from publishers
• Prepare context diagrams

Dr. Syed Atif Ali Shah 69


Dr. Syed Atif Ali Shah 70
Dr. Syed Atif Ali Shah 71
Book Supplier: Exploding Process 2

Dr. Syed Atif Ali Shah 72


THANK YOU
DR. SYED ATIF ALI SHAH
DEPARTMENT OF COMPUTER SCIENCE
AIR UNIVERSITY, ISLAMABAD.
[Link]@[Link]

Dr. Syed Atif Ali Shah 73

You might also like