Core Concepts of ER Model

Sql tutorial · PySpark.in

6. Modeling Databases

Before creating database tables, we first need to understand:

Database modeling helps us answer these questions.

One of the most commonly used techniques for database design is the:

ER Model (Entity Relationship Model)

The ER Model represents:

between real-world objects.

It acts as a blueprint for designing databases.

6.1 Core Concepts in ER Model

The ER Model consists of several important concepts.

Entity

A real-world object or concept is called an Entity.

Entities can be:

Examples of Entities

Real World Object

Entity

Student

Student

Employee

Employee

Product

Product

Company

Company

Real-Life Examples

John
Emma
Apple
Google

Each of these represents a real-world object, so they are entities.

Attributes of an Entity

Attributes are the properties or characteristics of an entity.

They describe the entity.

Example

Consider a Student entity.

Attribute

Value

name

John

age

29

city

Delhi

Here:

are attributes of the Student entity.

Another Example

name

age

Emma

25

Attributes:

name
age

Key Attribute

A key attribute uniquely identifies each entity.

No two entities can have the same key value.

Example

Consider the Student entity:

student_id

name

age

101

John

29

102

Emma

25

Here:

student_id

is the key attribute because it uniquely identifies every student.

Why Key Attributes Are Important

Key attributes help us:

Entity Type

An Entity Type is a collection of entities having the same attributes.

Example

Entity Type: Student

student_id

name

age

101

John

29

102

Emma

25

103

David

30

All students have the same attributes:

student_id
name
age

Therefore, they belong to the same entity type: Student.

Relationships

A relationship represents an association between entities.

Relationships show how entities are connected.

Example

Consider:

A customer places orders.

So:

Customer → places → Order

This association is called a relationship.

Types of Relationships

Relationships are classified based on how many entities are associated.

1. One-to-One Relationship (1:1)

In a One-to-One relationship:

Example: Person and Passport

One Person → One Passport
One Passport → One Person

Diagram

Real-Life Examples

2. One-to-Many Relationship (1:M)

In a One-to-Many relationship:

Example: Person and Cars

One Person → Many Cars
One Car → One Person

Diagram

Real-Life Examples

3. Many-to-Many Relationship (M:N)

In a Many-to-Many relationship:

Example: Students and Courses

One Student → Many Courses
One Course → Many Students

Diagram

Real-Life Examples

Cardinality Ratio

Cardinality defines the maximum number of relationships between entities.

It describes:

How many instances of one entity
can relate to another entity

Types of Cardinality

Cardinality

Meaning

1:1

One-to-One

1:M

One-to-Many

M:1

Many-to-One

M:N

Many-to-Many

Understanding Cardinality

1:1 Relationship

One Employee → One Locker

1:M Relationship

One Customer → Many Orders

M:1 Relationship

Many Employees → One Department

M:N Relationship

Many Students ↔ Many Courses

Applying ER Model Concepts

Let us understand ER modeling using a real-world application.

Example: E-Commerce Application

An e-commerce application contains entities such as:

Entity Types

Entity Type

Description

Customer

Application users

Product

Products sold online

Cart

Shopping cart

Address

Delivery addresses

Relationship 1 — Customer and Cart

A customer has only one cart.

A cart belongs to only one customer.

Relationship Type

Customer → Cart = One-to-One (1:1)

Diagram

Relationship 2 — Cart and Products

A cart can contain many products.

A product can exist in many carts.

Relationship Type

Cart → Products = Many-to-Many (M:N)

Diagram

Relationship 3 — Customer and Address

A customer can save multiple addresses.

Each address belongs to one customer.

Relationship Type

Customer → Address = One-to-Many (1:M)

Diagram

ER Model Summary for E-Commerce Application

Entity

Relationship

Entity

Type

Customer

owns

Cart

1:1

Cart

contains

Product

M:N

Customer

saves

Address

1:M

Why ER Modeling Is Important

ER modeling helps us:

More Sql tutorials

All tutorials · Try the free PySpark compiler · Practice challenges