Database Design and ER Diagram

Database design decide करता है आपका project अपना data कैसे store करता है, और एक entity-relationship diagram इसके लिए tool है: आप entities (चीज़ें जो आप store करते हैं), इनके attributes, और इनके बीच relationships identify करते हैं, तो data organised, consistent, और needless duplication से free हो।

10 min read · 6 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Design कीजिए कि Data कहाँ रहता है

लगभग हर project data store करता है, students, events, orders, records, और आप उस data को कैसे organise करते हैं यह हुगेली affect करता है क्या project अच्छी तरह काम करता है। इसे सही कीजिए, और सब कुछ consistent और query करना easy है; इसे गलत कीजिए, और आप हमेशा के लिए duplication और inconsistency से लड़ते हैं।

Database design इस structure को plan करना है, और classic tool है entity-relationship (ER) diagram, जो आपने DBMS में सीखा। यह lesson इसे आपके project पर apply करता है: entities, इनके attributes, और इनके बीच relationships identify करना, एक clean data blueprint produce करने के लिए इससे पहले आप एक भी table create करें।

Theory

Entities, Attributes, Relationships

एक ER diagram आपके data को तीन ingredients से model करता है।

Entities वे चीज़ें हैं जिनके बारे में आप data store करते हैं, आपके system के nouns: Student, Event, Registration। हर एक (roughly) एक table बनता है।

Attributes एक entity के properties हैं: एक Student के पास एक name, email, और id है; एक Event के पास एक title, date, और venue है। हर entity को एक primary key चाहिए, एक unique identifier (एक student id जैसा)।

Relationships entities को connect करती हैं: एक Student एक Event के लिए register करता है। Relationships में cardinality होती है, one-to-one, one-to-many, या many-to-many, describe करते हुए एक की कितनी दूसरे से relate करती हैं (एक student कई events के लिए register कर सकता है; एक event की कई registrations हैं)।

इन्हें अपनी requirements से draw कीजिए, और आपकी data structure map हो जाती है।

Formula

Duplication से बचने के लिए Normalise कीजिए

Good database design का एक key goal है redundancy घटाना, same data को कई जगहों पर store करने से बचना। यही है जो normalisation (DBMS से) achieve करता है: data को organise करना तो हर fact एक जगह रहे।

यह क्यों matter करता है: अगर एक student का email बहुत सारी rows के across duplicated है और वे इसे change करते हैं, आपको हर copy update करनी पड़ती है, और अगर आप एक miss करते हैं, data inconsistent हो जाता है (अब कौन सा correct है?)। हर data के हिस्से को एक बार store करके और relationships (keys) से link करके, आप इसे consistent और maintain करना easy रखते हैं। तो अपने entities और relationships को इस तरह design कीजिए कि वे हर fact को एक बार hold करें। एक clean, normalised design कोई भी code लिखने से पहले bugs की एक पूरी class रोकता है।

Quiz

आपके project के लिए एक ER diagram में, एक 'entity' क्या represent करता है?

  1. User interface की colour scheme
  2. एक चीज़ जिसके बारे में आप data store करते हैं (Student, Event, या Registration जैसी), attributes और एक primary key के साथ
  3. Database की speed
  4. Code में एक single function
Show the answer

एक चीज़ जिसके बारे में आप data store करते हैं (Student, Event, या Registration जैसी), attributes और एक primary key के साथ

एक ER diagram में, एक entity एक चीज़ represent करती है जिसके बारे में आप data store करते हैं, Student, Event, या Registration जैसी, और इसके attributes (इसके properties, name और email जैसे) और एक primary key (एक unique identifier) होते हैं। Option A, UI colour scheme, एक design/UX matter है, एक data entity नहीं। Option C, database speed, एक performance (non-functional) concern है, एक entity क्या है यह नहीं। Option D, एक single function, code logic है, एक data entity नहीं। Entities वे 'चीज़ें' (nouns) हैं जिनके बारे में आपका system information store करता है; attributes इन्हें describe करते हैं, और relationships इन्हें connect करती हैं, साथ में आपका data blueprint बनाते हुए।

Think first

कोई भी Tables Create करने से पहले एक ER Diagram से Database Design क्यों करें?

आप बस चलते-चलते tables create कर सकते थे। पहले एक ER diagram से data क्यों model करें? फिर tap कीजिए।

Show the answer

क्योंकि database वह FOUNDATION है जिस पर आपकी पूरी application built है, और इसकी structure में mistakes बाद में fix करना extremely costly होता है, तो इसे carefully model करना एक ER diagram से पहले, tables create करने और इनके against code लिखने से पहले, deep, painful problems रोकता है। सोचिए data structure कितनी central है: आपकी application का लगभग हर part database से पढ़ता और लिखता है, तो एक बार आपने tables create कर ली हैं और code, forms, queries, और features build कर लिए हैं जो इनकी structure पर depend करते हैं, वह structure change करने का मतलब है इससे connected हर चीज़ change करना। अगर आपने coding करते हुए ad hoc tables create कीं और बाद में discover किया design flawed था, एक ज़रूरी entity missing है, tangled relationships हैं, data हर जगह duplicated है, आप database AND उसे इस्तेमाल करने वाले सारे code दोनों के एक massive, error-prone reworking का सामना करते, अक्सर project में late जब आप इसे सबसे कम afford कर सकते। एक ER diagram आपको data design को UP FRONT सोचने देता है, paper पर (या एक diagram tool), जहाँ changes free हैं: आप सभी entities और relationships एक साथ देख सकते हैं, missing या wrong connections spot कर सकते हैं, primary keys decide कर सकते हैं, और duplication हटाने के लिए normalise कर सकते हैं, यह सब code में कुछ भी commit करने से पहले। यह एक clean, consistent structure produce करता है जो आपकी requirements support करता है और redundancy avoid करता है जो inconsistency bugs cause करती है। यह team को data की एक shared, clear picture भी देता है (essential जब कई लोग अलग-अलग parts build करते हैं), और यह आपकी report और presentation के लिए documentation बन जाता है। ER diagram, in effect, आपके data का blueprint है, और जैसे आप एक plan के बिना एक building का foundation नहीं डालते, आपको अपना database design किए बिना create नहीं करना चाहिए, क्योंकि बाकी सब इस पर rest करता है। पहले data model कीजिए, foundation सही पाइए, और project का बाकी हिस्सा solid ground पर खड़ा होता है। इस पर build करने से पहले data design कीजिए।

Summary

Key takeaways

  • Database design plan करता है आपका project data कैसे store करता है; entity-relationship (ER) diagram इसके लिए tool है (DBMS से)।
  • Entities वे चीज़ें हैं जिनके बारे में आप data store करते हैं (Student, Event, Registration), हर एक के साथ एक primary key।
  • Attributes एक entity की properties हैं (एक Student के पास name, email, id है)।
  • Relationships entities को connect करती हैं (एक Student एक Event के लिए register करता है) cardinality के साथ (one-to-one, one-to-many, many-to-many)।
  • Redundancy घटाने के लिए design normalise कीजिए, हर fact को एक बार store करते हुए, तो data consistent और maintainable रहे।
  • Tables create करने से पहले अपनी requirements से ER model design कीजिए, क्योंकि database वह foundation है जिस पर सब कुछ rest करता है।
  • Memory hook: entities (चीज़ें), attributes (properties), relationships (links); एक ER diagram से model कीजिए, normalise कीजिए, फिर build कीजिए।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Project Design and Architecture

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Database Design and ER Diagram · Project (Major-16) · Gri-Learn