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 ઠીક કરે છે.
  • યાદ રાખવાની યુક્તિ: 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