New: Try Voli The Bear, Fast package manager (and not only) for Windows
All topics / Relationships & Keys (Primary & Foreign)

Relationships & Keys (Primary & Foreign)

Why real data lives in several linked tables instead of one big one, what primary and foreign keys actually are, and how they let the database enforce that your records stay connected and consistent.

Download EPUB
  1. Why Split Data Into Tables One giant table repeats the same facts in row after row, which lets them drift out of sync; the fix is to store each kind of thing once, in its own table, and have the other tables reference it.
  2. Primary Keys A primary key is the one column whose value uniquely and permanently names each row, so the rest of the database has a stable thing to point at; auto-incrementing numbers usually beat real-world values for the job.
  3. Foreign Keys & Referential Integrity A foreign key is a column that holds another table's primary key, turning a loose number into an enforced link; it models one-to-many and (via junction tables) many-to-many, and lets the database refuse to create orphaned rows.