Curriculum
Course: SQL
Login
Text lesson

ER Diagram

 
Objectives
  • What is an ER diagram
  • Component of ER Diagram
  • Advantage of ER Diagram
  • Entity Relationshi Arrow Types
  • Cardinality
  • Mapping natural language parts of speech that are used to build sentences:
  • How to create and interpret ER diagrams?
  • Example of ER Diagram
 
Entity Relation Diagram
Entity-relationship (ER) diagrams are visual representations of a data model for a system. It defines entities, which can be objects or concepts within the system, as well as the relationships between them. ER diagrams are commonly used in database design to help developers understand the structure and organization of the data that needs to be stored. It also describes the relationships between different entities, such as customers and products, and can help improve the system’s efficiency. In addition, ER diagrams illustrate the logical structure of a system, which can help developers identify potential design errors and simplify the development process.
Component of ER Diagram

An ER diagram consists of several key components that help represent the structure of a database. Here’s a breakdown of these components:

Component

Definition

Sign Representation

Example

Entity

real objects and concepts with distinct existence

rectangles

hospital, patient, doctor

Attribute

characteristics of entities

ovals

patient's attributes are name, age, gender & diagnosis

Relationship

show how entities are related

diamonds

doctor - treatment - patient

Primary Key

uniquely identify each instance of an entity

undunderline PK

patient_id

Foreign Key

attributes that reference the primary key of another entity

dashed line

patient_id in the diagnosiss entity

Display entity and attributes with the shape

Image

Display entity and attributes with the foregin key

Image

Display relationship between two entites

Image

Entity’s Relationship

Relationships show how entities are related to one another. A database consists of various entities that establish different types of relationships with one another within a project. These relationships can be classified as one-to-one, one-to-many, or many-to-many. For example, between hospitals and patients, doctors and patients, and patients undergoing treatments. A patient may experience various diagnostic tests, such as ultrasound, X-rays, and blood tests. A cancer patient undergoes multiple treatments, such as radiotherapy, chemotherapy, and surgery, while a single chemotherapy treatment is prescribed for many patients.

As a result, the database enforces specific limitations that ensure data consistency. The purpose of entity relationships is to manage unnecessary data load and prevent alterations or deletions that could negatively impact the data’s intended purpose. This approach helps ensure data accuracy and integrity. In addition to helping ensure accurate data collection, it also helps ensure proper data use. 

Advantage of ER Diagram

Entity Relationship Diagrams are crucial for designing databases, providing clear visual models that simplify the relationships among entities and their attributes, accordingly making the work process much more efficient. common reasons of ER-Diagram are given below

Visualization

The ER diagram provides a clear overview of the database structure. This helps visualize the complex relationships and data flow in the database, making it easier to understand and visualize.

Efficient 

ER diagram’s role as a foundation for a database, providing required entities, attributes, and relationships are considered. It helps normalize the database, reduce redundancy, and ensure data integrity.

Communication

ER diagrams encourage collaboration among database designers, developers, and stakeholders, ensuring a mutual understanding of the data model. That normalizes requirements by delivering a visual tool for discussing and validating the data model with stakeholders.

Error Prevention

ER diagrams play a vital role in identifying possible issues during the design process, reducing the possibility of database errors. Diagrams are useful for troubleshooting and maintaining databases, making them easier to understand and fix.

Documentation and Maintenance

An ER diagram provides a complete description of the database schema. It simplifies the process of maintaining and updating the database over time. Diagrams assist with version control by visualizing modifications to the data model, making it easier to track and manage thoes changes.

Query Optimization

The ER diagram ensures a database structure that promotes efficient data retrieval and manipulation, as a result enhancing query optimization.

Support System Development

ER diagrams play a crucial role in the system development process by defining data requirements and relationships. The diagrams can influence application logic, system versions, and user interfaces.

Entity Relationship Arrow Types

Entity-relationship (ER) diagrams illustrate the relationships between different entities in database design. These diagrams use specific symbols, including arrows, to represent relationships.

In an ER diagram there are several types of line and its endpoint accourding to the chosen notation style.

A set of arrows can illustrate different types of relationships between entities; for example:

  • One-to-one relationships are usually indicated by a single line.
  • One-to-many or many-to-many relationships can be shown using a crow’s foot (three-pronged line).

Relations

Symbol

Shape

Example

One to one

1:1

A patient -- Register

One to Zero or one

1:0...1

A patient -- Register

One to Many

1:N

A patient -- Diagnosis

One to One or Many

1:1...N

A Patient -- A Doctor

One to Zero or Many

1:0...N

A Patient -- Kidney Transplanet

Many to Many

N;N

Patients -- Diagnosis

One or Many to One or Many

1...N:1...N

Patients -- Treatment

Zero or Many to Zero to Many

0...N:0...N

Patients -- chemptherapy protocol

*Multiplicity: The outer edge of the relationship

*Mandatory: this relationship come mandatory. it can be zero or one

*Optiona: This relation is optional 

*Empty zero: Optional relationship

*Vertical line [ | ]: A Multiplicity of one and a mandatory is represented by a vertical line which

*Crow’s foot notation: Many relationship

Cardinality

In a relationship, there are a number of attributes corresponding to the two entities involved. Relationships between these objects are defined by expressions, which usually refer to their primary and foreign keys. Determine whether a relationship is one-to-one, one-to-many, or many-to-many.

Mapping natural language

ER diagram components can be compared with parts of speech, showing how an ER diagram is related to natural language.

  • Entity Type –> Common noun <– Doctor
  • Entity –> Proper noun <– Peter Chan
  • Relationship –> Verb <— Register
  • Attribute for entity –> Adjective <–  specialist (Surgeon | Doctor Petter Chan is a thoracic surgery specialist)
  • Attribute to relationship –> Adverb <– annually (Dr. Chan annually registers on the council to keep the license.)
Â