Categories

Advertisement
⏱️ 12 min read

Entity Relationship (ER) Model

N
By NotesMind
Advertisement

ER Model की Definition

ER Model (Entity Relationship Model) एक high-level conceptual data model है जो database implement करने से पहले उसकी structure design करने के लिए use होता है।

इसमें तीन मुख्य चीज़ें होती हैं:

Component क्या होता है
Entity Real-world objects — जैसे Student, Teacher
Attribute Entity की properties — जैसे Name, Age
Relationship Entities के बीच का संबंध — जैसे "Studies"

ER Model = Database का नक्शा (Blueprint)


ER Model क्यों ज़रूरी है?

बिना ER Model के ER Model के साथ
Design confusing होता है Design clear और organized होता है
Duplicate data आ जाता है Redundancy कम होती है
Maintenance मुश्किल होती है Implementation आसान होती है
Relationships गलत बन जाते हैं Relationships properly defined होते हैं
Team में confusion होती है Better communication होती है

Real-life example: मान लीजिए आप एक College Management System बना रहे हैं जिसमें Students, Teachers, Courses, Departments हैं। Tables बनाने से पहले यह तय करना होगा — कौन सा Student कौन सा Course पढ़ता है? कौन सा Teacher कौन सा Subject पढ़ाता है? यही सब ER Diagram में पहले design किया जाता है।


Entity क्या होती है?

Entity कोई भी real-world object होती है जिसके बारे में database में जानकारी store की जाती है। यह कोई व्यक्ति, वस्तु, स्थान या concept हो सकता है।

Examples: Student, Teacher, Employee, Customer, Book, Product, Hospital

Strong Entity

जिस entity का अपना Primary Key होता है और वह independently exist कर सकती है — उसे Strong Entity कहते हैं।

Example:

Student
──────────────
Roll No ← Primary Key
Name
Age

Student बिना किसी दूसरी entity पर depend किए exist करती है।

Weak Entity

जो entity किसी दूसरी entity के बिना exist नहीं कर सकती — वह Weak Entity कहलाती है। इसका अपना complete Primary Key नहीं होता।

Example:

Employee ──────→ Dependent
                 ──────────
                 Name
                 Age

Dependent (परिवार का सदस्य) तभी exist करता है जब Employee exist करे।

Strong vs Weak Entity — अंतर

Strong Entity Weak Entity
Primary Key होती है Complete Primary Key नहीं होती
Independent होती है दूसरी entity पर depend करती है
अकेले exist कर सकती है अकेले exist नहीं कर सकती
Rectangle से दिखाते हैं Double Rectangle से दिखाते हैं

Attributes क्या होते हैं?

Attribute किसी entity की property या characteristic होती है।

Example — Student entity के attributes:
Roll No, Name, Age, Address, Phone Number

Types of Attributes — Attributes के प्रकार

1. Simple Attribute

जिसे और छोटे parts में divide नहीं किया जा सकता।

Examples: Gender, Age, Salary

2. Composite Attribute

जिसे और छोटे parts में divide किया जा सकता है।

Example:

Address
   ├── House No
   ├── City
   ├── State
   └── PIN Code
3. Single-Valued Attribute

जिसमें सिर्फ एक value होती है।

Example: Age = 20 — एक student की एक ही उम्र होती है।

4. Multi-Valued Attribute

जिसमें एक से ज़्यादा values हो सकती हैं।

Example:

Phone Numbers ├── 9876543210 └── 9988776655

एक person के कई phone numbers हो सकते हैं।

5. Derived Attribute

जो किसी दूसरे attribute से calculate किया जाता है।

Example: Date of Birth से Age calculate होती है — इसलिए Age एक Derived Attribute है।

6. Stored Attribute

जो physically database में store होता है।

Example: Date of Birth physically store होती है, Age उससे derive होती है।

सभी Attribute Types — एक नज़र में

Type क्या होता है Example
Simple Divide नहीं हो सकता Age, Gender
Composite Parts में divide होता है Address
Single-Valued एक ही value Age = 20
Multi-Valued कई values Phone Numbers
Derived Calculate होता है Age (DOB से)
Stored Physically stored Date of Birth

ER Diagram में Attribute Symbols

Symbol क्या दर्शाता है
Rectangle Entity
Oval Simple Attribute
Double Oval Multi-Valued Attribute
Dashed Oval Derived Attribute
Underlined text Primary Key

Keys क्या होती हैं?

Key वह attribute (या attributes का set) है जो किसी record को uniquely identify करती है। Keys के बिना duplicate records को रोकना impossible होता है।

Types of Keys — Keys के प्रकार

1. Super Key

Attributes का कोई भी ऐसा set जो record को uniquely identify करे।

Example — Student Table:

Roll Name Email
101 Rahul rahul@gmail.com

Possible Super Keys: Roll, Email, Roll + Name, Roll + Email

2. Candidate Key

Super Key का minimum version — यानी जितने कम attributes में unique identification हो सके।

Example: Roll और Email — दोनों अकेले ही student को uniquely identify कर सकते हैं।

3. Primary Key

Candidate Keys में से जो एक key official तौर पर चुनी जाए।

Rules:

  • Unique होनी चाहिए
  • NULL नहीं हो सकती
  • Stable होनी चाहिए (बदले नहीं)

Example: Student table में Roll No → Primary Key

4. Alternate Key

जो Candidate Keys Primary Key नहीं बनीं — वे Alternate Keys कहलाती हैं।

Example:

  • Candidate Keys: Roll, Email
  • Primary Key = Roll
  • Alternate Key = Email
5. Composite Key

जब एक से ज़्यादा attributes मिलकर Primary Key बनाएँ।

Example — Enrollment Table:

StudentID CourseID
101 DBMS

Primary Key = StudentID + CourseID (दोनों मिलकर)

6. Foreign Key

जो key दो tables को आपस में जोड़ती है।

Example:

Student Table:

Roll Name
101 Rahul

Enrollment Table:

Roll Course
101 DBMS

यहाँ Enrollment table में RollForeign Key है जो Student table से link करती है।

सभी Keys — एक नज़र में

Key क्या होती है Example
Super Key Unique identify करने वाला कोई भी set Roll, Roll+Name
Candidate Key Minimum Super Key Roll, Email
Primary Key Chosen Candidate Key Roll No
Alternate Key बची हुई Candidate Keys Email
Composite Key 2+ attributes की Key StudentID + CourseID
Foreign Key दो tables को जोड़ने वाली Key Roll in Enrollment

Relationship क्या होती है?

Relationship दो या दो से ज़्यादा entities के बीच का संबंध दर्शाती है।

Example: Student → Studies → Course

Types of Relationships — Relationships के प्रकार

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

एक entity का दूसरी entity से सिर्फ एक ही instance से relation।

Example: एक Person का एक ही Passport होता है।

Person ──────── Passport
2. One-to-Many (1:M)

एक entity का कई instances से relation।

Example: एक Teacher कई Students को पढ़ाता है।

Teacher ├── Student A ├── Student B └── Student C

3. Many-to-One (M:1)

कई entities का एक instance से relation।

Example: कई Employees एक ही Department में काम करते हैं।

Employee A ──┐ Employee B ──┼──→ Department Employee C ──┘

4. Many-to-Many (M:N)

कई entities का कई instances से relation — यह सबसे common relationship है।

Example: कई Students कई Subjects पढ़ते हैं।

 

Students ←──────→ Subjects

Relationships — एक नज़र में

Type Example Real-life
1:1 Person–Passport एक व्यक्ति, एक passport
1:M Teacher–Students एक teacher, कई students
M:1 Employees–Department कई employees, एक department
M:N Students–Subjects कई students, कई subjects

Cardinality क्या होती है?

Cardinality यह specify करती है कि एक entity के कितने instances दूसरी entity के instances से related हो सकते हैं।

Example: एक Teacher → कई Students — Cardinality = 1:M

Types: 1:1, 1:M, M:1, M:N — जो relationships में ऊपर समझाए गए हैं।


Participation Constraints

Participation यह बताती है कि किसी entity का relationship में हिस्सा लेना ज़रूरी है या optional

Total Participation

हर entity को relationship में participate करना ज़रूरी होता है।

Example: हर Employee किसी न किसी Department में ज़रूर होता है।

Partial Participation

Participation optional होती है।

Example: हर Customer ज़रूरी नहीं कि Order place करे।

Type Matlab Example
Total Participation हर entity participate करे Employee → Department
Partial Participation Optional participation Customer → Order

ER Diagram Symbols — सभी Symbols एक जगह

Symbol Meaning
Rectangle Entity
Double Rectangle Weak Entity
Oval Attribute
Double Oval Multi-Valued Attribute
Dashed Oval Derived Attribute
Diamond Relationship
Double Diamond Identifying Relationship (Weak entity के लिए)
Underlined Attribute Primary Key

Complete ER Diagram Example — Library Management System

         (BookID)        (Title)
            ○               ○
            |               |
     ┌─────────────┐
     │    BOOK     │
     └─────────────┘
            |
          BORROWS
            ◇
            |
     ┌─────────────┐
     │   STUDENT   │
     └─────────────┘
      /      |      \
  (Roll)  (Name)  (Phone)
                      ◎ ← Multi-valued
  • BOOK और STUDENT — Entities
  • BORROWS — Relationship
  • BookID और Roll — Primary Keys
  • Phone — Multi-Valued Attribute (double oval)

ER Diagram को Tables में Convert करना

यह सबसे important practical step है। ER Diagram design होने के बाद उसे actual database tables में convert करते हैं।

ER Diagram:

Student ──── Studies ──── Course

Tables बनती हैं:

Student Table:

Roll Name Dept
101 Rahul CSE

Course Table:

CourseID CourseName
C101 DBMS

Enrollment Table (M:N resolve करने के लिए):

Roll CourseID
101 C101

Enrollment table Many-to-Many relationship को resolve करती है — यह एक Junction Table है।


Real-Life ER Diagram Examples

Banking System

Entity Relationships
Customer Customer owns Account
Account Branch manages Account
Loan Customer takes Loan
Branch Branch manages multiple Accounts

Hospital Management

Entity Relationships
Doctor Doctor treats Patient
Patient Patient receives Medicine
Medicine Medicine prescribed in Appointment
Appointment Doctor-Patient ke beech

E-Commerce System

Entity Relationships
Customer Customer places Order
Product Order contains Product
Order Order linked to Payment
Payment Customer makes Payment

Chapter Summary — एक नज़र में

Concept क्या है
ER Model Database का visual blueprint
Entity Real-world object (Student, Teacher)
Attribute Entity की property (Name, Age)
Relationship Entities का connection (Studies)
Keys Records को uniquely identify करती हैं
Cardinality Relationship की count (1:1, 1:M, M:N)
Participation Mandatory या optional participation
Conversion ER Diagram → Relational Tables

FAQ

Q1. ER Model और ER Diagram में क्या फर्क है?

ER Model एक concept है — यह define करता है कि database में entities, attributes और relationships कैसे होंगे। ER Diagram उस concept का visual representation है — यानी boxes, ovals और diamonds से बना actual diagram। Model = idea, Diagram = उस idea की drawing।

Q2. Primary Key और Foreign Key में क्या अंतर है?

Primary Key एक table में records को uniquely identify करती है — जैसे Student table में Roll No। Foreign Key दो tables को आपस में जोड़ती है — जैसे Enrollment table में Roll No जो Student table को refer करता है। Primary Key जिस table में हो वहाँ unique होती है; Foreign Key दूसरी table में उसी value को reference करती है।

Q3. Many-to-Many relationship को database में कैसे handle करते हैं?

Many-to-Many (M:N) relationship को directly एक table में store नहीं किया जा सकता। इसके लिए एक Junction Table (Bridge Table) बनाई जाती है जिसमें दोनों tables की Primary Keys Foreign Keys की तरह store होती हैं। जैसे — Students और Courses के बीच एक Enrollment Table बनती है।

Advertisement

💬 Leave a Comment & Rating