Database and Table Basics
This page brings together why tables are split, how a DB differs from Excel, and how the split tables connect again through parent/child relationships and references.
Why Split Tables
Tables were split to group data of the same kind together, reduce duplication, and connect them through relationships.
DB vs Excel
- Managing duplication — In Excel, a user's name is typed again for every reel on a single sheet. A DB keeps it only once in users and references it by id → duplication removed, edits in one place.
- Enforcing integrity — A DB uses an FK to block "reels from a user who doesn't exist" entirely (inserting a nonexistent user_id=999 raises an error). In Excel, any value can slip in through a typo.
- Relationships and queries — A DB instantly combines multiple tables with JOIN and aggregates with GROUP BY. Even large data is fast thanks to indexes
- Concurrency/rules — Multiple users can access it, and the engine guarantees constraints such as UNIQUE and NOT NULL
- Why split tables: to separate data of different kinds (people/videos/likes/comments), store it without duplication, and connect it again through relationships (normalization)
Parent Table and Child Table
Of two tables connected by an FK, the side being referenced (the original that holds the value) is the parent, and the side doing the referencing (the side borrowing that value) is the child. For example, reels.user_id references users.user_id, so users is the parent and reels is the child.
- When inserting data, parent first, child later (
users->reels->likes/comments) - When deleting data, child first, parent later (this is why
DROP TABLEin01_schema.sqlgoes in the ordercomments->likes->reels->users)
What Is a Reference
A child table does not copy and store the whole parent row. It stores only the parent's PK value and connects in the sense of "pointing to the row that has this value." For example, reels.user_id = 4 does not store the name traveler_ji directly; it only "references" the row in the users table where user_id = 4. That is why if you later change users.full_name, you don't need to fix reels one by one.
Summary
| Concept | Key point |
|---|---|
| Why split tables | Separate data of different kinds, store it without duplication, and reconnect it through relationships (normalization) |
| DB vs Excel | Managing duplication, enforcing integrity (FK), JOIN/GROUP BY/indexes, concurrency and constraints (UNIQUE, NOT NULL) |
| Parent / child | The referenced side is the parent, the referencing side is the child. Insert parent first, delete child first |
| Reference | Points to the parent row by storing only its PK value instead of copying it → the child needs no edits when the parent value changes |
Source: Codyssey-B1/B6-1
