Candidate Key
Candidate Key ဆိုတာ ဘာလဲ?
Section titled “Candidate Key ဆိုတာ ဘာလဲ?”Candidate Key ဆိုတာ Table ထဲရှိ Record တစ်ခုချင်းစီကို တိတိကျကျ သီးသန့် ခွဲခြားပေးနိုင်တဲ့ Field (သို့မဟုတ် Field အစုအဝေး) ဖြစ်ပါတယ်။
“Candidate” (ကိုယ်စားလှယ်လောင်း) ဆိုတဲ့ နာမည်အတိုင်းပဲ၊ ဒီ Key တွေဟာ Primary Key အဖြစ် ရွေးချယ်ခံရဖို့ အရည်အချင်း ပြည့်မီနေကြတဲ့ Key များ ဖြစ်ပါတယ်။ Table တစ်ခုမှာ Candidate Key တစ်ခုထက်မက ရှိနိုင်ပါတယ်။
Candidate Key ရဲ့ မဖြစ်မနေ စည်းမျဉ်းများ
Section titled “Candidate Key ရဲ့ မဖြစ်မနေ စည်းမျဉ်းများ”Field တစ်ခုဟာ Candidate Key ဖြစ်ဖို့ဆိုရင် အောက်ပါ စည်းမျဉ်းများနှင့် ကိုက်ညီရပါမယ်:
- Unique ဖြစ်ရမည်: Candidate Key Value သည် တခြား Record များနှင့် ထပ်တူညီ၍ မရပါ။
- NOT NULL ဖြစ်ရမည်: Value လွတ်နေခြင်း (
Null) လုံးဝ ခွင့်မပြုပါ။ - Immutability (မကြာခဏ မပြောင်းလဲရပါ): Candidate Key Value သည် အချိန်နဲ့အမျှ ခဏခဏ ပြောင်းလဲနေတဲ့ Data မျိုး မဖြစ်သင့်ပါ။ (ဥပမာ - ဖုန်းနံပါတ်သည် ပြောင်းလဲနိုင်သဖြင့် Candidate Key အဖြစ် မသင့်တော်ပါ။)
Artificial Candidate Key (Surrogate Key)
Section titled “Artificial Candidate Key (Surrogate Key)”တစ်ခါတလေမှာ Table ထဲက ဘယ် Natural Field မှ (Unique မဖြစ်လို့) Candidate Key အဖြစ် သုံးလို့ မရတာမျိုး ကြုံရတတ်ပါတယ်။ (ဥပမာ - cars Table မှာ ကားအမျိုးအစားနဲ့ အရောင်လောက်ပဲ ပါတဲ့အခါမျိုး)
ဒီလို အခြေအနေမျိုးမှာ System ကနေ အလိုအလျောက် တိုးပေးမယ့် Auto-increment id (ဥပမာ - 1, 2, 3, 4) ဆိုတဲ့ Field အသစ်တစ်ခု ဖန်တီးပြီး Candidate/Primary Key အဖြစ် သုံးကြပါတယ်။ ဒါကို Surrogate Key (Artificial Candidate Key) လို့ ခေါ်ဆိုပါတယ်။