Key attribute, derived attribute, multi-valued attribute

Attributes कई किस्मों में आते हैं: एक key attribute एक record को uniquely पहचानता है, एक derived attribute दूसरों से CALCULATE होता है (date of birth से age) तो आप उसे कभी store नहीं करते, और एक multi-valued attribute कई values रखता है (कई phone numbers) और संकेत देता है कि आपको एक अलग table चाहिए।

10 min read · 8 cards · 2 checks

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


Theory

तीन ब्योरे, तीन समस्याएँ

Meera के customer record में तीन पेचीदा ब्योरे हैं:

  • एक customer number जो कभी दोहराना नहीं चाहिए,
  • एक age, जो हर birthday बदलती है,
  • और एक customer जिसने तीन phone numbers दिए हैं।

हर एक एक attribute है, पर हर एक अलग बर्ताव करता है, और इन्हें गलत संभालना असली bugs पैदा करता है: duplicate customers, गलत ages, phone numbers जो नहीं समाएँगे। Attributes types में आते हैं, और इन्हें जानना ही आप इन traps से कैसे बचते हैं। इनमें से दो types एक ऐसे design की शुरुआती चेतावनियाँ भी हैं जिसे ठीक करने की ज़रूरत है।

At a glance

Attribute types

TypeमतलबE/R symbol
Keyएक record को uniquely पहचानता हैUnderlined ellipse
Derivedदूसरों से compute (age)Dashed ellipse
Multi-valuedकई values रखता है (phones)Double ellipse
Compositeहिस्सों में बँटता है (address)sub-ellipses वाला ellipse

Theory

तीन जो सबसे ज़्यादा मायने रखते हैं

  • Key attribute: हर record को uniquely पहचानता है, customer_id। कोई दो customers इसे साझा नहीं करते। Underlined दिखाया।
  • Derived attribute: इसकी value दूसरों से calculate हो सकती है, date_of_birth से age, price x quantity से total। आपको इसे store नहीं करना चाहिए; ज़रूरत पर compute कीजिए। एक dashed ellipse के रूप में दिखाया।
  • Multi-valued attribute: एक entity के लिए एक से ज़्यादा value रखता है, एक customer के कई phone numbers। एक double ellipse के रूप में दिखाया। यह एक red flag है: यह एक अकेले column में साफ़-सुथरे नहीं समाता।

Quiz

Meera हर customer की 'age' को table में एक तय number के रूप में store करती है। यह एक बुरा विचार क्यों है?

  1. Age एक derived attribute है; इसे date of birth से compute करना चाहिए, store नहीं, वरना यह बासी हो जाता है
  2. Age बहुत ज़्यादा storage जगह लेती है
  3. Age एक database में एक number नहीं हो सकती
  4. Ages को हमेशा text के रूप में store करना चाहिए
Show the answer

Age एक derived attribute है; इसे date of birth से compute करना चाहिए, store नहीं, वरना यह बासी हो जाता है

Age date of birth से derived है और हर साल बदलती है, तो एक store की age अगले birthday के अगले दिन गलत होती है जब तक कोई उसे update न करे। स्थिर date_of_birth store कीजिए और age ज़रूरत पर compute कीजिए। Derived values store करना बासी, असंगत data का एक क्लासिक स्रोत है, ठीक इसीलिए derived attributes एक dashed ellipse से खींचे जाते हैं और storage से बाहर रखे जाते हैं।

Think first

तीन phone numbers की समस्या

एक customer तीन phone numbers देता है। Meera का मन करता है कि उन्हें एक 'phone' cell में '9876..., 9123..., 9000...' के रूप में ठूँस दे। एक multi-valued attribute एक design चेतावनी क्यों है, और सही इलाज क्या है?

Show the answer

कई values को एक cell में ठूँसना उस नियम को तोड़ता है कि हर cell एक value रखता है (first normal form)। आप उन्हें ठीक से search या count नहीं कर सकते, ठीक Unit 2 वाली 'name, phone एक column में' गड़बड़। इलाज: phone numbers को उनकी अपनी अलग table दीजिए (customer_id + phone_number, हर phone की एक row)। एक multi-valued attribute प्रकृति का यह बताने का तरीका है कि एक नई table चाहिए, normalization का बीज।

Watch out

Marks कहाँ कटते हैं

Derived attributes (age, totals) store करना, उन्हें compute कीजिए, store मत कीजिए (वे बासी हो जाते हैं)। एक multi-valued attribute को एक cell में ठूँसना, इसे एक अलग table चाहिए। E/R symbols गड्डमड्ड करना: key = underlined, derived = dashed ellipse, multi-valued = double ellipse, composite = sub-parts वाला ellipse। और एक composite attribute (address = street + city + pincode) को इसके atomic हिस्सों में बाँटना चाहिए। ये symbol-और-purpose जोड़ियाँ मानक exam marks हैं।

Theory

आपने अभी normalization का preview देखा

दो attribute types, multi-valued और composite, शाब्दिक रूप से वे समस्याएँ हैं जिन्हें ठीक करने के लिए first normal form मौजूद है। आप इलाज का नाम पड़ने से पहले बीमारी से मिल चुके हैं। और key attribute अगले lesson में keys के एक पूरे परिवार में फैलने वाला है। Attribute types शब्दावली हैं; keys और normalization वहाँ हैं जहाँ वे अपनी कमाई करते हैं। आगे: keys का पूरा परिवार।

Summary

Key takeaways

  • Key attribute: हर record को uniquely पहचानता है (customer_id); underlined दिखाया।
  • Derived attribute: दूसरों से compute (DOB से age); इसे store मत कीजिए, वरना बासी हो जाता है; dashed ellipse।
  • Multi-valued attribute: कई values रखता है (कई phones); double ellipse; एक अलग table चाहिए।
  • Composite attribute: हिस्सों में बँटता है (address = street+city+pincode)।
  • Multi-valued और composite attributes ठीक वही हैं जिन्हें first normal form ठीक करता है।
  • याद रखने का hook: key पहचानता है, derived calculate होता है (कभी store नहीं), multi-valued का मतलब एक नई table।

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 Concepts of Database

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

Key attribute, derived attribute, multi-valued attribute · Data Processing and Analysis (DPA) · Gri-Learn