ER/EER मॉडल्स को रिलेशनल स्कीमाज़ में मैप करना

DIPLOMA_CSE / DBMS

Mapping ER/EER Models to Relational Schemas in Hindi

Table of Contents

Conversion of Entities and Relationships to Tables in Hindi

**Entity-Relationship (ER) Model** का उपयोग database का **Graphical Representation** बनाने के लिए किया जाता है। लेकिन, Database Management System (DBMS) में data को **Tables** के रूप में store किया जाता है। इस प्रक्रिया में, **Entities, Attributes, और Relationships** को **Relational Tables** में बदलना होता है। यहाँ हम विस्तार से समझेंगे कि यह प्रक्रिया कैसे होती है।

1. Entities को Tables में Convert करना

**Entity** वह object होती है, जिसके पास **Attributes (गुणधर्म)** होते हैं। **Relational Schema** में, प्रत्येक **Entity** को एक अलग **Table** के रूप में बदला जाता है। **Entity का Primary Key (PK)** उसकी पहचान को दर्शाता है।

Conversion Rules:

  • प्रत्येक **Entity** के लिए एक **Table** बनता है।
  • **Attributes** को **Columns** के रूप में रखा जाता है।
  • हर Table में एक **Primary Key (PK)** जरूर होनी चाहिए।

Example:

Entity Name Attributes (Columns) Primary Key
Student Student_ID, Name, Age Student_ID

2. Relationships को Tables में Convert करना

जब दो या अधिक **Entities** एक-दूसरे से जुड़े होते हैं, तो उसे **Relationship** कहा जाता है। **ER Model में Relationships** को **Lines और Diamonds** से दर्शाया जाता है। **Relational Schema** में, **Relationships** को **Foreign Key (FK)** द्वारा represent किया जाता है।

Conversion Rules:

  • अगर **1:1 Relationship** हो, तो किसी एक **Table** में दूसरी **Entity की Primary Key** को **Foreign Key** के रूप में रखा जाता है।
  • अगर **1:M Relationship** हो, तो **Many Side वाले Table** में **One Side की Primary Key** को **Foreign Key** के रूप में रखा जाता है।
  • अगर **M:N Relationship** हो, तो एक अलग **Table** बनाया जाता है, जिसमें दोनों Entities की **Primary Keys** को **Foreign Keys** के रूप में रखा जाता है।

Example:

Relationship Entities Involved Foreign Key
Enrolls Student - Course Student_ID (Students Table से), Course_ID (Courses Table से)

3. Entities और Relationships का SVG Diagram

नीचे **Entities और Relationships को Relational Schema** में बदलने की प्रक्रिया को **SVG Diagram** से दर्शाया गया है।

Student Course Enrolls

Handling Weak Entities and Composite Attributes in Hindi

**Weak Entity** वह entity होती है जो अकेले अपनी पहचान नहीं बना सकती और उसे एक **Strong Entity** पर निर्भर रहना पड़ता है। **Composite Attribute** वे attributes होते हैं, जो खुद छोटे-छोटे sub-attributes में विभाजित किए जा सकते हैं। **Relational Schema** में इन दोनों concepts को सही तरीके से represent करना बहुत जरूरी होता है। यहाँ हम विस्तार से समझेंगे कि **Weak Entities और Composite Attributes** को **Tables** में कैसे बदला जाता है।

1. Weak Entities को Tables में Convert करना

**Weak Entity** की पहचान के लिए कोई **Primary Key (PK)** नहीं होती, इसलिए इसे **Strong Entity** की **Primary Key** के साथ जोड़ा जाता है। **Weak Entity को Represent करने के लिए** एक **Discriminator Attribute** का उपयोग किया जाता है, जो इसे अलग-अलग entities से अलग करता है।

Conversion Rules:

  • Weak Entity के लिए एक **Table** बनाया जाता है।
  • Weak Entity की पहचान के लिए **Primary Key (PK) + Strong Entity की Primary Key** को मिलाकर **Composite Key** बनाई जाती है।
  • Weak Entity और Strong Entity के बीच **Identifying Relationship** होता है, जिसे **Foreign Key (FK)** से दर्शाया जाता है।

Example:

Entity Name Attributes (Columns) Primary Key Foreign Key
Customer Customer_ID, Name Customer_ID None
Order (Weak Entity) Order_ID, Order_Date, Customer_ID (FK) Order_ID + Customer_ID (Composite Key) Customer_ID (FK)

2. Composite Attributes को Tables में Convert करना

**Composite Attribute** ऐसा attribute होता है, जिसे छोटे-छोटे **Sub-Attributes** में तोड़ा जा सकता है। उदाहरण के लिए, **Full Name** को **First Name** और **Last Name** में विभाजित किया जा सकता है। **Relational Schema** में, प्रत्येक **Sub-Attribute** को अलग-अलग **Columns** के रूप में represent किया जाता है।

Conversion Rules:

  • Composite Attribute को तोड़कर अलग-अलग **Columns** बनाए जाते हैं।
  • अगर Composite Attribute के अंदर कई sub-values हैं, तो एक अलग **Table** बनाया जा सकता है।
  • Parent Table और Sub-Attributes Table के बीच **Foreign Key (FK)** का उपयोग किया जाता है।

Example:

Entity Name Composite Attribute Converted Columns
Person Address Street, City, State, Zip

3. Weak Entities और Composite Attributes का SVG Diagram

नीचे **Weak Entity और Composite Attributes** को दर्शाने वाला **SVG Diagram** दिया गया है।

Customer Order Places Address Street City State

Mapping of Superclass/Subclass Relationships in Hindi

**Superclass और Subclass Relationship** तब बनता है जब एक entity को सामान्य (Generalization) या विशिष्ट (Specialization) तरीके से वर्गीकृत किया जाता है। **Superclass** वह entity होती है जो सामान्य attributes को रखती है, और **Subclass** वह होती है जो विशेष attributes को जोड़ती है। Relational Schema में Superclass और Subclass को **Three Approaches** से Map किया जाता है। इस टॉपिक में हम इन तरीकों को विस्तार से समझेंगे और उनके उदाहरण देखेंगे।

1. Superclass/Subclass Mapping Approaches

Superclass और Subclass को **Relational Schema** में दर्शाने के लिए तीन मुख्य तरीके होते हैं:

  • Single Table Inheritance: Superclass और Subclass को एक ही टेबल में स्टोर किया जाता है।
  • Multiple Tables Inheritance: Superclass और Subclass के लिए अलग-अलग टेबल बनाई जाती हैं।
  • Hybrid Approach: कुछ attributes को एक टेबल में और कुछ को अलग-अलग टेबल में स्टोर किया जाता है।

2. Single Table Inheritance (One Table Strategy)

इस तरीके में **Superclass और सभी Subclass** को एक ही टेबल में रखा जाता है। इसमें एक **Discriminator Column** (Type Column) का उपयोग किया जाता है जो यह दर्शाता है कि कौन-सी row किस **Subclass** से संबंधित है।

Example:

Person_ID Name Type Salary (for Employee) GPA (for Student)
1 Rahul Employee 50000 NULL
2 Amit Student NULL 8.5

3. Multiple Tables Inheritance (Table Per Class Strategy)

इस तरीके में **Superclass** और प्रत्येक **Subclass** के लिए अलग-अलग टेबल बनाई जाती हैं। Superclass की Primary Key, Subclass की Table में **Foreign Key** के रूप में स्टोर की जाती है।

Example:

Superclass Table: Person

Person_ID Name
1 Rahul
2 Amit

Subclass Table: Employee

Person_ID Salary
1 50000

Subclass Table: Student

Person_ID GPA
2 8.5

4. Hybrid Approach (Mixed Strategy)

इस तरीके में, **Superclass** की सामान्य जानकारी एक **Parent Table** में रखी जाती है, और विशिष्ट **Subclass Attributes** अलग-अलग टेबल में स्टोर किए जाते हैं। इसका उपयोग तब किया जाता है जब कुछ attributes सामान्य हों और कुछ विशिष्ट।

5. Superclass/Subclass Relationship का SVG Diagram

नीचे **Superclass और Subclass Relationship** को दर्शाने वाला **SVG Diagram** दिया गया है।

Person Employee Student

FAQs

**Superclass** वह entity होती है जिसमें सभी **Common Attributes** होते हैं, और **Subclass** वह entity होती है जो विशेष attributes को रखती है। उदाहरण के लिए, **Person** एक Superclass हो सकता है, और उसके Subclass **Employee** और **Student** हो सकते हैं।
**Single Table Inheritance** में Superclass और Subclass की सारी जानकारी एक ही **Table** में रखी जाती है। इसमें एक **Type Column** (Discriminator Column) का उपयोग किया जाता है जो यह बताता है कि row किस Subclass से संबंधित है।
**Multiple Tables Inheritance** में Superclass और प्रत्येक Subclass के लिए अलग-अलग टेबल बनाई जाती हैं। **Superclass Table की Primary Key, Subclass Table में Foreign Key** के रूप में स्टोर की जाती है।
**Hybrid Approach** में कुछ attributes को **Superclass Table** में रखा जाता है और कुछ को अलग-अलग **Subclass Tables** में स्टोर किया जाता है। यह तरीका तब उपयोग किया जाता है जब कुछ attributes सभी entities के लिए समान होते हैं और कुछ विशेष होते हैं।
**Superclass और Subclass Mapping** डेटा को व्यवस्थित तरीके से स्टोर करने में मदद करता है। इससे **Redundancy** कम होती है और डेटा को **Efficient तरीके से Query** किया जा सकता है।
**Foreign Key** का उपयोग **Superclass और Subclass के बीच Relationship** बनाने के लिए किया जाता है। इससे एक **Superclass Entity** को उसके संबंधित **Subclass Entity** से जोड़ा जा सकता है।