🗂️ Basic ER Diagram
Learn Database Design Visually — Step by Step
🌟 What is an ER Diagram?
Imagine you want to design a database for a college. You need to store information about:
👨🎓 Students
📚 Courses
👨🏫 Teachers
🏢 Departments
An ER Diagram is like a map of the database. It helps us understand what information we need and how different pieces of information are connected.
ER = Entity + Relationship
👉 Click the buttons below to learn each concept visually.
Imagine you want to design a database for a college. You need to store information about:
👨🎓 Students
📚 Courses
👨🏫 Teachers
🏢 Departments
An ER Diagram is like a map of the database. It helps us understand what information we need and how different pieces of information are connected.
ER = Entity + Relationship
👉 Click the buttons below to learn each concept visually.
⬛ 1. Entity
Simple Meaning:
An entity is a real-world thing about which we want to store information.
Think of an entity as a "thing" in our real world.
An entity is a real-world thing about which we want to store information.
Think of an entity as a "thing" in our real world.
🎓 College Example
STUDENT
TEACHER
COURSE
For a college database:
👨🎓 Student → Entity
👨🏫 Teacher → Entity
📚 Course → Entity
🏢 Department → Entity
👨🎓 Student → Entity
👨🏫 Teacher → Entity
📚 Course → Entity
🏢 Department → Entity
⚙️ Think of It Like This
Entity = Thing we want to remember information about.
For example:
If we want to store information about students, STUDENT becomes an entity.
For example:
If we want to store information about students, STUDENT becomes an entity.
🎨 ER Symbol
Rectangle = Entity
⬛ STUDENT
⬛ STUDENT
🔵 2. Attribute Types
Simple Meaning:
An attribute is information that describes an entity.
If STUDENT is the entity, then:
Name, Roll Number, Phone, Address and Date of Birth can be attributes.
An attribute is information that describes an entity.
If STUDENT is the entity, then:
Name, Roll Number, Phone, Address and Date of Birth can be attributes.
1️⃣ Simple Attribute
A simple attribute cannot be meaningfully divided into smaller
parts for the purpose of the model.
Example: Age
Salary
Gender
Example: Age
Salary
Gender
STUDENT
Age
Symbol: Single Oval
Example: Age
Example: Age
2️⃣ Composite Attribute
A composite attribute can be divided into smaller meaningful
attributes.
Name
First Name
Middle Name
Last Name
Example:
Name = Bijan Krishna Paul
Name can be divided into:
First Name = Bijan
Middle Name = Krishna
Last Name = Paul
Therefore, Name is a Composite Attribute.
Name = Bijan Krishna Paul
Name can be divided into:
First Name = Bijan
Middle Name = Krishna
Last Name = Paul
Therefore, Name is a Composite Attribute.
Remember:
Composite = One attribute made up of several smaller attributes.
Composite = One attribute made up of several smaller attributes.
3️⃣ Multivalued Attribute
A multivalued attribute can contain
more than one value for the same entity.
STUDENT
Phone Number
One student may have:
Phone 1 → 9876543210
Phone 2 → 9123456780
Phone 3 → 9001122334
So the student has multiple phone numbers.
Phone 1 → 9876543210
Phone 2 → 9123456780
Phone 3 → 9001122334
So the student has multiple phone numbers.
ER Symbol:
Double Oval
⭕⭕ Phone_Number
Memory Trick:
Multiple values → Multivalued Attribute
Double Oval
⭕⭕ Phone_Number
Memory Trick:
Multiple values → Multivalued Attribute
4️⃣ Derived Attribute
A derived attribute is a value that can be
calculated from other information.
STUDENT
Date of Birth
Age
Suppose:
Date of Birth = 15 August 2005
Current Date = 31 August 2026
The student's age can be calculated from the Date of Birth.
Age = Current Date − Date of Birth
Date of Birth = 15 August 2005
Current Date = 31 August 2026
The student's age can be calculated from the Date of Birth.
Age = Current Date − Date of Birth
ER Symbol:
Dashed Oval
Memory Trick:
Calculated value → Derived Attribute
Dashed Oval
Memory Trick:
Calculated value → Derived Attribute
📊 Attribute Summary
| Type | Easy Meaning | Example | Symbol |
|---|---|---|---|
| Simple | Cannot be divided | Age | Single Oval |
| Composite | Can be divided | Name | Oval + Sub-Ovals |
| Multivalued | Multiple values | Phone | Double Oval |
| Derived | Calculated value | Age | Dashed Oval |
🔷 3. Relationship
Simple Meaning:
A relationship tells us how two or more entities are connected.
A relationship tells us how two or more entities are connected.
STUDENT
ENROLLS
COURSE
Think about a college:
A student ENROLLS in a course.
Therefore:
STUDENT → ENROLLS → COURSE
A student ENROLLS in a course.
Therefore:
STUDENT → ENROLLS → COURSE
🎨 ER Symbol
Diamond = Relationship
The diamond is placed between the entities.
The diamond is placed between the entities.
🌍 Real-World Examples
CUSTOMER → BUYS → PRODUCT
STUDENT → ENROLLS → COURSE
EMPLOYEE → WORKS FOR → DEPARTMENT
DOCTOR → TREATS → PATIENT
STUDENT → ENROLLS → COURSE
EMPLOYEE → WORKS FOR → DEPARTMENT
DOCTOR → TREATS → PATIENT
🔢 4. Cardinality
Simple Meaning:
Cardinality tells us:
"How many?"
It describes how many instances of one entity can be associated with another entity.
Cardinality tells us:
"How many?"
It describes how many instances of one entity can be associated with another entity.
1️⃣ One-to-One (1 : 1)
One person has one passport.
PERSON 1 ───── 1 PASSPORT
PERSON 1 ───── 1 PASSPORT
2️⃣ One-to-Many (1 : N)
One department can have many employees.
DEPARTMENT 1 ───── N EMPLOYEE
DEPARTMENT 1 ───── N EMPLOYEE
3️⃣ Many-to-Many (M : N)
Many students can enroll in many courses.
STUDENT M ───── N COURSE
STUDENT M ───── N COURSE
Easy Example:
👨🎓 One student can study several courses.
📚 One course can contain many students.
Therefore:
STUDENT M : N COURSE
👨🎓 One student can study several courses.
📚 One course can contain many students.
Therefore:
STUDENT M : N COURSE
🧠 Easy Memory Trick
1 : 1 → One with One
1 : N → One with Many
M : N → Many with Many
1 : N → One with Many
M : N → Many with Many
🔑 5. Primary Key
Simple Meaning:
A primary key is an attribute that uniquely identifies each record.
Think of it as the "unique ID" of an entity.
A primary key is an attribute that uniquely identifies each record.
Think of it as the "unique ID" of an entity.
STUDENT
Roll_No
Roll_No
Suppose we have:
Roll_No = 101 → Rahul
Roll_No = 102 → Anita
Roll_No = 103 → Arjun
Each student has a different Roll_No. Therefore:
Roll_No = Primary Key
Roll_No = 101 → Rahul
Roll_No = 102 → Anita
Roll_No = 103 → Arjun
Each student has a different Roll_No. Therefore:
Roll_No = Primary Key
🔑 Easy Memory Trick:
Primary Key = Unique Identity
Like an ID card number that identifies one person.
Primary Key = Unique Identity
Like an ID card number that identifies one person.
⬛ 6. Weak Entity
Simple Meaning:
A weak entity is an entity that cannot be uniquely identified by its own attributes alone.
It depends on another entity for identification.
A weak entity is an entity that cannot be uniquely identified by its own attributes alone.
It depends on another entity for identification.
🎓 Easy Example
EMPLOYEE
HAS
DEPENDENT
Suppose an employee has a dependent.
Dependent Name = Rahul
Another employee could also have a dependent named Rahul. Therefore, the dependent's name alone may not uniquely identify the dependent.
We may identify the dependent using:
Employee_ID + Dependent_Name
Dependent Name = Rahul
Another employee could also have a dependent named Rahul. Therefore, the dependent's name alone may not uniquely identify the dependent.
We may identify the dependent using:
Employee_ID + Dependent_Name
ER Symbol:
Double Rectangle = Weak Entity
Weak Entity depends on a strong entity.
Double Rectangle = Weak Entity
Weak Entity depends on a strong entity.
🎓 7. Complete ER Diagram Example
Problem:
A college wants to store information about students and courses. A student can enroll in multiple courses, and a course can have multiple students. Let's create the ER model step by step.
A college wants to store information about students and courses. A student can enroll in multiple courses, and a course can have multiple students. Let's create the ER model step by step.
1 Find the Entities
We identify the main things:
👨🎓 STUDENT
📚 COURSE
👨🎓 STUDENT
📚 COURSE
2 Find the Attributes
STUDENT
Roll_No
Name
Date_of_Birth
Phone_Number
COURSE
Course_ID
Course_Name
Roll_No
Name
Date_of_Birth
Phone_Number
COURSE
Course_ID
Course_Name
3 Identify the Primary Keys
STUDENT:
🔑 Roll_No
COURSE:
🔑 Course_ID
🔑 Roll_No
COURSE:
🔑 Course_ID
4 Find the Relationship
Student
↓
ENROLLS
↓
Course
5 Find the Cardinality
One student can enroll in many courses.
One course can contain many students.
Therefore:
M : N
One course can contain many students.
Therefore:
M : N
6 Final ER Diagram
STUDENT
🔑 Roll_No
Name
Date_of_Birth
Phone_Number
🔑 Roll_No
Name
Date_of_Birth
Phone_Number
M
ENROLLS
N
COURSE
🔑 Course_ID
Course_Name
🔑 Course_ID
Course_Name
STUDENT M : N COURSE
Many Students ↔ Many Courses
Many Students ↔ Many Courses
📖 8. ER Diagram Symbol Guide
| Symbol / Shape | Name | Meaning |
|---|---|---|
| ▭ | Rectangle | Entity |
| ⬭ | Oval | Attribute |
| ◇ | Diamond | Relationship |
| Double Oval | Multivalued Attribute | Multiple values |
| Dashed Oval | Derived Attribute | Calculated value |
| Underlined Attribute | Primary Key | Unique identifier |
| Double Rectangle | Weak Entity | Dependent entity |
🧠 Super Easy Memory Trick
⬛ Rectangle
ENTITY = Thing
🔵 Oval
ATTRIBUTE = Information
🔷 Diamond
RELATIONSHIP = Connection
⭕⭕ Double Oval
MULTIVALUED = Many Values
Dashed Oval
DERIVED = Calculated
ENTITY = Thing
🔵 Oval
ATTRIBUTE = Information
🔷 Diamond
RELATIONSHIP = Connection
⭕⭕ Double Oval
MULTIVALUED = Many Values
Dashed Oval
DERIVED = Calculated
🌟 ER Diagram in One Minute
ENTITY
What?
What?
→
ATTRIBUTE
What information?
What information?
→
RELATIONSHIP
How connected?
How connected?
→
CARDINALITY
How many?
How many?
🎯 ER Diagram = A Visual Map of a Database
ENTITY = Thing | ATTRIBUTE = Information | RELATIONSHIP = Connection | CARDINALITY = How Many?
ENTITY = Thing | ATTRIBUTE = Information | RELATIONSHIP = Connection | CARDINALITY = How Many?
No comments:
Post a Comment