Thuta Learning
ရှာဖွေရန်
IntermediateData & Databasesbeginner

Normalization နှင့် Schema Design

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Normalization နှင့် Schema Design concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ SQL/command ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် အသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

Normalization ရဲ့ရည်ရွယ်ချက်က update anomaly၊ duplicate facts နှင့် inconsistent data ကိုလျှော့ဖို့ပါ။ User email ကို enrollment row တိုင်းပြန်သိမ်းမည့်အစား user table မှာတစ်ခါသိမ်းပြီး key ဖြင့်ချိတ်ပါတယ်။ ဒါပေမယ့် reporting/performance အတွက် denormalization လုပ်နိုင်ပြီး source of truth နဲ့ sync strategy ကိုရှင်းရပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Tutorial၊ lesson နှင့် user ကို independent entities ခွဲပြီး enrollment ကို many-to-many bridge အဖြစ်ထားမယ်။ Lesson progress ကို enrollment+lesson pair အဖြစ် model လုပ်ခြင်းက user/tutorial fields ထပ်သိမ်းခြင်းထက် constraint များချိတ်ရလွယ်ပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

text
users 1 ───< enrollments >─── 1 tutorials

                               └──< lesson_progress >── 1 lessons

tutorials 1 ───< lessons

Rule: each fact lives once; relationships carry foreign keys.
You should see
Tutorial Platform entity relationship map တစ်ခုရမည်။

၅ မိနစ် စမ်းကြည့်

Comment feature အတွက် author၊ tutorial/lesson target၊ body နဲ့ timestamps ကို duplication မဖြစ်အောင် model ဆွဲပါ။

သတိလေးတစ်ချက်

Normalization level ကို rule ကျက်ပြီးမရွေးပါနှင့်။ Query pattern၊ integrity နဲ့ change frequency ကိုပါစဉ်းစားပါ။

PostgreSQL — Data DefinitionPostgreSQL Global Development Group

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Normalization level ကို rule ကျက်ပြီးမရွေးပါနှင့်။ Query pattern၊ integrity နဲ့ change frequency ကိုပါစဉ်းစားပါ။
  • နမူနာ code ကို production data ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test database နှင့် recoverable backup ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

Comment feature အတွက် author၊ tutorial/lesson target၊ body နဲ့ timestamps ကို duplication မဖြစ်အောင် model ဆွဲပါ။

You'll know it worked when: Tutorial Platform entity relationship map တစ်ခုရမည်။

Normalization နှင့် Schema Design | Thuta Learning