Feedback Form

ER to Relational Model Mapping in Hindi

ER to Relational Mapping का Overview

जब हम Database Design बनाते हैं, तब शुरुआत में हम ER Model (Entity-Relationship Model) का उपयोग करते हैं। यह model हमें real-world objects (जैसे Student, Teacher, Course आदि) और उनके बीच के संबंध (relationships) को समझने में मदद करता है।

लेकिन कंप्यूटर में data को store करने के लिए हम सीधे ER Diagram का उपयोग नहीं कर सकते। इसके लिए हमें इसे Relational Model (Table के रूप में) में बदलना पड़ता है। इसी प्रक्रिया को ER to Relational Mapping कहा जाता है।

सरल शब्दों में:
ER Diagram → Tables (Relations)

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

  • Database को सही structure में store करने के लिए
  • Data redundancy (बार-बार data आने) को कम करने के लिए
  • Data को आसानी से retrieve और manage करने के लिए
  • Real-world concept को database में सही तरीके से दिखाने के लिए

ER to Relational Mapping के मुख्य Steps

ER Diagram को relational schema में बदलते समय हम कुछ basic rules follow करते हैं:

  • Entity → Table
  • Attributes → Columns
  • Primary Key → Unique identifier
  • Relationships → Foreign Key या नई Table

Mapping of Regular Entity Types

Regular Entity (जिसे Strong Entity भी कहते हैं) वह entity होती है जिसकी अपनी Primary Key होती है। इसे relational model में convert करना सबसे आसान होता है।

Regular Entity को Table में कैसे बदलें?

Regular Entity को relational table में बदलने के लिए नीचे दिए गए steps follow करें:

  1. Entity का नाम → Table का नाम बनता है
  2. Entity के सभी attributes → Table के columns बनते हैं
  3. Entity की Primary Key → Table की Primary Key बनती है

Example (उदाहरण)

मान लीजिए हमारे पास एक Student entity है, जिसके attributes हैं:

  • Student_ID (Primary Key)
  • Name
  • Age
  • Course

तो इसे relational table में ऐसे बदलेंगे:

Student Table

Student_ID (PK) Name Age Course
101 Rahul 20 BCA

Important Points (ध्यान रखने योग्य बातें)

  • हर entity के लिए अलग table बनाया जाता है
  • Primary Key हमेशा unique होनी चाहिए
  • Attributes को सही data type के साथ define करना चाहिए
  • Simple attributes सीधे column बनते हैं

Multi-Valued Attribute का Case

अगर किसी entity में कोई attribute एक से ज्यादा values रख सकता है (जैसे Phone Number), तो उसे अलग table में store किया जाता है।

उदाहरण:

Student (Student_ID, Name)

Phone (Student_ID, Phone_Number)

यहाँ Student_ID को दोनों tables में use करके relation बनाया जाता है।

Composite Attribute का Case

Composite attribute (जो कई parts में होता है) को छोटे-छोटे attributes में तोड़ दिया जाता है।

उदाहरण:

  • Address → Street, City, State

तो table में अलग-अलग columns बनेंगे:

Address (Street, City, State)

Summary (सारांश)

Regular Entity Mapping सबसे basic और important step है ER to Relational Mapping में। इसमें हम entity को सीधे table में बदलते हैं और उसके attributes को columns में। अगर कहीं special case (multi-valued या composite attribute) आता है, तो उसके अनुसार अलग handling की जाती है।

Mapping of Weak Entity Types

Weak Entity वह entity होती है जिसकी अपनी कोई Primary Key नहीं होती। यह अपनी पहचान के लिए किसी दूसरी strong entity पर निर्भर करती है।

इसे पहचानने के लिए Owner Entity (Strong Entity) की Primary Key और Weak Entity के partial key को मिलाकर एक Composite Primary Key बनाई जाती है।

Weak Entity Mapping के Steps

  • Weak Entity के लिए एक अलग table बनाएं
  • Owner Entity की Primary Key को include करें (Foreign Key के रूप में)
  • Weak Entity के attributes को columns बनाएं
  • Primary Key = Owner की PK + Weak Entity का Partial Key

Example

Employee (Emp_ID) एक strong entity है और Dependent एक weak entity है:

  • Dependent_Name (Partial Key)
  • Age

Table बनेगा:

Dependent (Emp_ID, Dependent_Name, Age)

यहाँ Primary Key = (Emp_ID + Dependent_Name)

Mapping of One-to-One (1:1) Relationships

One-to-One relationship में एक entity का एक ही record दूसरी entity के एक ही record से जुड़ा होता है।

Mapping Method

  • किसी एक table में दूसरे table की Primary Key को Foreign Key के रूप में जोड़ते हैं
  • आमतौर पर उस entity में FK रखा जाता है जिसमें participation total हो

Example

Person और Passport के बीच 1:1 relation है:

  • Person (Person_ID, Name)
  • Passport (Passport_ID, Issue_Date)

Mapping:

Person (Person_ID, Name, Passport_ID)

यहाँ Passport_ID Foreign Key है।

Important Points

  • FK किसी भी एक side में रखा जा सकता है
  • Total participation होने पर उसी table में FK रखना बेहतर होता है
  • दोनों tables को merge भी किया जा सकता है (अगर जरूरत हो)

Mapping of One-to-Many (1:N) Relationships

One-to-Many relationship में एक entity का एक record दूसरी entity के कई records से जुड़ा होता है।

Mapping Method

  • "Many side" वाले table में "One side" की Primary Key को Foreign Key के रूप में जोड़ते हैं

Example

Department और Employee के बीच 1:N relation है:

  • Department (Dept_ID, Dept_Name)
  • Employee (Emp_ID, Name)

Mapping:

Employee (Emp_ID, Name, Dept_ID)

यहाँ Dept_ID Foreign Key है।

Important Points

  • Foreign Key हमेशा "Many side" में जाती है
  • इससे relationship को efficiently represent किया जा सकता है
  • Data duplication से बचाव होता है

Mapping of Many-to-Many (M:N) Relationships

Many-to-Many relationship में दोनों entities के कई records आपस में जुड़े होते हैं।

Mapping Method

  • एक नई table (Relation Table / Junction Table) बनाई जाती है
  • दोनों entities की Primary Keys को इसमें Foreign Keys के रूप में जोड़ा जाता है
  • इन दोनों को मिलाकर Composite Primary Key बनती है

Example

Student और Course के बीच M:N relation है:

  • Student (Student_ID, Name)
  • Course (Course_ID, Course_Name)

Mapping:

Enrollment (Student_ID, Course_ID)

यहाँ दोनों Foreign Keys मिलकर Primary Key बनाते हैं।

Important Points

  • M:N relation को सीधे represent नहीं किया जा सकता
  • हमेशा एक नई table बनानी पड़ती है
  • Relation table में extra attributes भी add किए जा सकते हैं (जैसे Marks, Date)

Summary (सारांश)

ER to Relational Mapping में Weak Entity और विभिन्न प्रकार के Relationships को सही तरीके से table में बदलना बहुत जरूरी है। हर relationship का अपना अलग mapping तरीका होता है:

  • Weak Entity → Composite Primary Key के साथ table
  • 1:1 → किसी एक table में Foreign Key
  • 1:N → Many side में Foreign Key
  • M:N → नई Junction Table

इन rules को समझकर हम एक सही और efficient relational database बना सकते हैं।